Custom Server Control RaisePostBack not firing

I have a composite server control which is made up of custom server controls.

one of the custom server controls implements IPostBackEventHandler (I am using the C# interface implementation pattern) however, it's RaisePostBack event never gets fired when it should. The page does post back with all the correct form data (Correct EventArgs and EventTarget) but still the event never fires.

The way I understand the page lifecycle (correct me if I'm wrong), the RaisePostBack event of the page gets fired before the CreateChildControls event of the controls on it. If the RaisePostBack event of the page tries to find the custom control by it's name and the name (UniqueId) doesn't get set until the CreateChildControls event, how does this ever worK?

Thanks,

CJ.
LVL 3
cjmosAsked:
Who is Participating?
 
Ted BouskillConnect With a Mentor Senior Software DeveloperCommented:
Ah yes it is related because the mechanisms are the same. Page Initialization (setting page IDs and firing CreateChildControls) fires before event handlers.  The following link from Microsoft discuss it: http://msdn2.microsoft.com/en-us/library/ms178472.aspx

Can you send me a simplified copy of the page I can run locally to analyze?
0
 
Ted BouskillSenior Software DeveloperCommented:
You need to look into 'Event Bubbling'.  There is a sample on this page: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/standard/button.aspx
0
 
cjmosAuthor Commented:
tedbilly,

Thanks for your reply. I know all about event bubbling, the problem I'm having is that I have no event to bubble up from in the first place.

CJ.
0
 
cjmosAuthor Commented:
Tedbilly, thanks for your help. I have managed to solve my problem. What I hadn't quite understood is that CreateChildControls is fired at many points in the lifecycle depending on whether of not it is needed. I had assumed that it was only fired by the page after the OnLoadComplete event and you had to manually fire it if you needed it at any other time.

My original problem: If you have a control that implements IPostBackEventHandler, the Page will call it's EnsureChildControls before it's RaisePostBackEvent to ensure that all of the child controls are created for the event to fire. My problem was that my server control was creating it's child controls outside of the CreateChildControls method so EnsureChildControls wasn't doing anything useful. I eventually realised this while examining the source of System.Web.UI.Page in reflector. However the article provided was useful in better understanding the page lifecycle.

CJ.
0
All Courses

From novice to tech pro — start learning today.