What Control is loaded first on "Load"?

utilitaire

Regular
Joined
May 4, 2005
Messages
77
Here's the problem:

I have a webform with many usercontrols. Those controls override the OnInit method, and the OnLoad method. The code runs fine, but I have some problem synchronizing all this. I have a certain routine I would like to execute each time a page is called by a client. This routine has to be done before ANY usercontrol is Init or Loaded. The question is: how do I do that? Where do I have to put the code in order to be sure It will be called before ANY other code? I tried in the «Init()» method of the main Page. It doesn't work since this «init» method is called after all controls in the page are called. Here's the scenario:

1) A client make a request.
2) The Page checks if the language in the URL (www.mysite.com/en/) is valid. My valid languages are "en" and "fr". If any other languages are specified, I redirect the client to a valid default language.
3) After the redirection, the new page (the good one) is executed, with all the controls in it. The «init» method is called for all controls, etc.

I want to make sure the step 2 is executed before step 3. I'm sure you faced this kind of problem. Any suggestion?

PS: Dont suggest me to do that in the global.asa, since the session_onstart method is only called once, and not each time the client make a new request for a page.
 
I'm going to suggest global.asax, but not the Session sub. Can you do it as part of the Begin Request? This fires each and everytime a page from the application is requested.

Visual Basic:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
  ' Fires at the beginning of each request
End Sub
 
wayneph said:
I'm going to suggest global.asax, but not the Session sub. Can you do it as part of the Begin Request? This fires each and everytime a page from the application is requested.

Visual Basic:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
  ' Fires at the beginning of each request
End Sub


thank you so much! I didn't event know this method was fired each time a page is requested!! Simple and perfect! Thank you again! :)
 
Back
Top