Question ASP Page life cycle (last event)

Gibou

Active member
Joined
Mar 4, 2009
Messages
25
Location
Paris
Programming Experience
5-10
Hello,

After some readings, I'm not convinced.
What is the last event throwed by an asp WebPage ?

There is my problem: I have some <div> blocks and I hide them with javascript at the end of the page.

I want to show only one block, depending on the "?do" param value.
So I want to check the param value and make a call to a javascript method at the end of the page. What is the right event i should handle ? I've tried SaveStateComplete and LoadComplete but it does not work :s

Thanks !
 
If you enable the trace feature you will see the following life cycles to the trace output:

aspx.page Begin PreInit
aspx.page End PreInit
aspx.page Begin Init
aspx.page End Init
aspx.page Begin InitComplete
aspx.page End InitComplete
aspx.page Begin PreLoad
aspx.page End PreLoad
aspx.page Begin Load
aspx.page End Load
aspx.page Begin LoadComplete
aspx.page End LoadComplete
aspx.page Begin PreRender
aspx.page End PreRender
aspx.page Begin PreRenderComplete
aspx.page End PreRenderComplete
aspx.page Begin SaveState
aspx.page End SaveState
aspx.page Begin SaveStateComplete
aspx.page End SaveStateComplete
aspx.page Begin Render
aspx.page End Render

However you should use the Init event handler
VB.NET:
Protected Overloads Overrides Sub OnPreInit(ByVal e As EventArgs)
        MyBase.OnPreInit(e)
        ' ToDo: something
End Sub

Btw, I guess you have a code like this on the client-side:
VB.NET:
document.getElementById(contentToHide).style.display = "none";
right?

Well i would suggest a bit different approach.

Set the div elements runat=server e.g.
VB.NET:
<div id="myDiv1" runat="server" visible='<%# if(condition to be evaluated, "true", "false") %>' />
Hope this helps
 
Thank you, I take note of your advice about the Init event. Thanks :)

About the "visible" method. I prefer mine because on the load of the page, the div is always hidden unless the user does not have the javascript activated. In that case, the div is shown and will never be hidable.
If the user has js activated, he will be able to hide/show the div block :)

Thanks again :)
 
Ok then use pure JavaScript code. Just get the "?do" param value and assign it to e.g. hidden field.

Rough example:

VB.NET:
function SetVisibility(){
var h = document.getElementById(hiddenObject);
   if (h.value=="false"){
       document.getElementById(contentToHide).style.display = "none";
   }
}
Now just call this from the body onLoad event handler.

<body onLoad="SetVisibility();">
...

</body>
 
Back
Top