views:

248

answers:

2

Hi, I am needing to create some dynamic controls at Page_Load in the consumer webpart. In the Provider webpart I did some hacking and got it so I could get a controls value before viewstate is loaded in Page_Init.

So basically what I want is for webparts to be able to communicate before Page_Load.

[ConnectionConsumer("FormRID Consumer","FormRIDConsumer")]
public void InitializeProvider(MyControl.IFormRID provider)
{
    theProvider = provider;
    FormRID = theProvider.FormRID;
}

That method doesn't get called until after Page_Load. This is a big problem for me because my consumers Page_Load depends on FormRID being set and accurate. I can't move my Page_Load code into Page_LoadComplete either because I am needing to create dynamic controls with viewstate(viewstate isn't restored after Page_Load)

So is there some work around I can use so that I can communicate before Page_Load.

+1  A: 

Hi Earlz, Have you tried subscribing to the web part zone's Init event and placing your InitializeProvider() there? I believe it is fired before OnLoad or OnInit events of user controls and web forms.

TSmith
Do you mean the Page_Init of the webpart's codebehind?
Earlz
Maybe you could give a little more information? I'm still a bit new to webparts. How would you initialize the communication manually through the Page_Init on the webpart manager's page codebehind?
Earlz
No, not the Page or Control init, but the WebPartZone container object has an "Init" and a "Load" event. The "Init" will fire before a page class or control class' Init. However, I am not sure if the control nested within the WebPartZone will be in a valid state at that time. In the VS Designer, if you click the webpart zone housing your control, and then go to Properties and switch your view to the "Event" view (lighting bolt), you will see the event.
TSmith
An Init event handler will be added to your codebehind page class, but it's not related to the page's Page_Init. Hope that helps...should looke something like:protected void WebPartZone1_Init(object sender, EventArgs e){}
TSmith
according to http://msdn.microsoft.com/en-us/library/ms366536.aspx so it would be pure hackery to get connections before Load, so I'm thinking I'll just roll my own communication method
Earlz
You might be able to use a ConnectionZone.http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webpartconnection.aspx
TSmith
A: 

I ended up having to create my own webpart communication.

It ended up much cleaner than ASP.Net's and communication can happen as early as OnInit inside of the webparts.

Earlz