Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Order Headache 1

Status
Not open for further replies.

0ddball

Technical User
Nov 6, 2003
208
GB
I'm having a bit of a mare here. There's something I need to do and I can't work out the correct order in which to do it. Let me set the scene:

When the user fires off a search using the search control it Response.Redirect()s and puts the search parameters in the query string. This works no problem - the page loads and renders without a problem.

It adds in some controls to the page at this point - a next button, a back button, and a number of 'page' buttons (depending on how many pages there are).

Here is where the problem arises.

A use clicks on the button to go to page 8.

The page initialises, loads and binds - ONLY THEN DOES MY CLICK EVENT FIRE.

This means that any controls my click event causes to be loaded are not rendered to the stream do not bind to their events.

If the user then clicks *another* page button they get the page state that SHOULD have been displayed for the previous click event. This continues click after click.

I guess what I need to know is how do I load controls onto the page in a server-side event without messing everything up. It seems such a natural thing to do!


Yet another unchecked rambling brought to you by:
Oddball
 
What is the nature of multiple pages? Not entirely clear here.
 
Code:
Entry Page
|
|--> Search Page (Displays Results) <-|
        |                             |
        |_[Postback New Results Page]_|



The postback is fired by a LinkButton.

I want to use that even to add a certain number of controls to the page.

I can't bind and register the controls. The events fire after all the relevent stages of the page lifecycle have happened.


Yet another unchecked rambling brought to you by:
Oddball
 
Oddball - let me kick this back up and see if someone with a little more insight can give you a bit of advice -- sounds like you might be running into a situation where you might want to trigger some of these events during Page initiation, etc., something I have not had the need to develop - there are several here at this forum who might be able to give you a little bit better direction, hang in there.
 
try the Page_PreRender event dude, just shift ur Page_Load code to the PreRender event...

Known is handfull, Unknown is worldfull
 
nah, the Init event fires before the click event, i think thats his problem jbenson. :)

Known is handfull, Unknown is worldfull
 
PreRender is too late - my controls won't bind to their events.

I feel there is no solution to this problem - I've currently fudged it by reloading the page with the query string altered.


Yet another unchecked rambling brought to you by:
Oddball
 
>>PreRender is too late - my controls won't bind to their events.


dont get it, what do u mean by they dont bind to their events?

Known is handfull, Unknown is worldfull
 
If, say, there is an Click event in my use control - if I add the control to the page in the PreRender event that event no longer fires.


Yet another unchecked rambling brought to you by:
Oddball
 
in which case u have to split it,

load the dynamic controls in the Init event like Jim said and write the redirection in the prerender event, if such a kind of split is impossible then only workarounds have to be done...

Known is handfull, Unknown is worldfull
 
This is really winding me up. It's cropped up again in another piece of code I've written.

What is it with ASP.net that means it can't late bind controls?

I seriously think this may be something wrong with the way I write my code and I'd appreciate some short and punchy advice as to what sort of code to put in which event during the page lifecycle.

It's not something that you find on the net very often - if someone can put it well enough it may even be worth stars :D


Yet another unchecked rambling brought to you by:
Oddball
 
There's a very good article on the page lifecycle and dynamic controls by a poster who used to frequent these forums (tgreer). Check out his article here:


Hopefully this will explain how (and why) the events execute in the order that they do.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.
 
I forgot to tip my hat to you here ca8.

Have a star.


Yet another unchecked rambling brought to you by:
Oddball
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top