make user control run before page?

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

It appears myButton_OnClick is triggering in my user control AFTER its
parent's Page_Load already runs. Is there a way to make the parent Page_Load
to run afterwards?

I'm changing a session variable when a user clicks on a button in a user
control. The parent page reads in the session variable. Obviously, this
isn't going to work if the parent has already done its thing.

I'm looking for an alternative, but adding code to every page negates the
reason for using the user control in the first place: re-use!

-Max
 
Hi there,

Unfortunatelly you can not change the order of event's executing:(
To see the events order when you use user control in an aspx page look at
this page : http://dotnet.dwteam.com/demos/pageevents.aspx ( click on Submit
button)
May be you should think of some other way of doing what you actually - for
example to work with the sessions variables in the Page PreRender event.

Regards
Martin
 
Hmmm, well I found a solution: just added a response.redirect on the user
control which causes the page to refresh (page load is called twice) with
the new session variable. I'm not crazy about the concepts people come up
with on communicating between user controls and pages. When you have a lot
of pages, placing special code in each page so the user control can become
exposed programmatically is simply not the ways of OOP. I'm hoping the next
version of .NET includes templates: that should solve some of these
problems.

-Max
 
Back
Top