UserControl, button click and Page_Load?

  • Thread starter Thread starter Olav Tollefsen
  • Start date Start date
O

Olav Tollefsen

I have a rather fundamental ASP.NET question.

On my page I have a search text box for user input, a button (which invokes
a event handler on the page) and a user control to display the results. The
button event handler will get a data set from a database and then calls a
method in the user control to transfer the dataset to the control. Then it
should render it's results to the page.

My problem is that the order of events after the button is clicked is like
this:

1) Page_Load for the ASP.NET page is called
2) Page_Load for my user control is called (which is not initialized with
the search results yet)
3) Button event handler is called

The problem is that the user control should be rendered after the button
event has been executed and not before.

What is the correct method to achieve this?
 
Instead of the load event you could move your code to the PreRender event ,
which happens after all the control events. So by
then everything should be initialized properly.
 
Back
Top