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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ted BouskillSenior 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.