Freigeben über


Web Part Connections and Page Life Cycle

This post won't be particularly detailed, but I hope to post an actual sample in the future that folks could compile and watch the the lifecycle in the Output window.

I ran across this while implementing a non-standard behavior in connected webparts in MOSS. So, here is the problem: imagine that you have a page with two web parts that you want to connect (say via IWebPartField), but the challenge is that you only want the callback for the connection to fired upon the click of a different control (e.g., input type=submit) on the screen. Here is what will happen. The page will load and the event for the submit click will fire then the wire-up of the connection interface callback will happen and subsequently the callback will fire. So, leaving out other events, because they aren't relative to the discussion it looks something like: Load->Submit_OnClick->Connection Interface to assign callback->Connection Callback to get data. This presents a problem if you want to get the data from the connected part within the Submit click as it does not exist yet. Thus, to get the desired behavior you have to basically set a flag in the submit_OnClick to indicate the click happened and then in the callback for the connected web part check to see if the OnClick flag is true and execute a method that contains the code that you would have normally put directly in the OnClick event.

If that description seems unclear, check back soon for a post with commented code to help clarify the matter. However, the net is that the click event fires before the connected webpart has gotten the information from its source and that, to me, seems counter intuitive as I would have expected the wire-up and callback for the connection to happen prior to any control's click event so that I would have access within the click events to what should be that latest state of the connected webparts.

Comments