Should I use the PreRender event

S

STom

I have several user controls where I am not using viewstate.

In the OnLoad, I call functions that will take the data out of the form
fields and save the data into a session object. Then I display what is in
the session object when the control is displayed to the client.

I have been reading about the control execution lifecycle and it seems that
PreRender might be of better use than the OnLoad event.

For example, if in the OnLoad event, I call SaveSessionData which does
something like:
If Not (Request.Form(Me.txtFirstName.UniqueID)) Is Nothing Then
Session("Person").FirstName =
Request.Form(Me.txtFirstName.UniqueID)
End If

and then call GetSessionData which does:
Me.txtFirstName.Text = Session("Person").FirstName

Is it not better to make the GetSessionData call in the prerender event?

BTW, the reason I have two separate functions to save and get the session
data is because in GetSessionData there are some other things I have to do
to set dropdowns etc.

Thanks.

STom
 
O

Oleg Ogurok

Instead of using this approach and peeking into Request.Form() directly, you
should attach event handlers to your controls and work with the posted
values there.
For example, you can attach an event handler for txtFirstName.TextChanged.
In this case, at postback you will have the newly entered text available as
txtFirstName.Text, but only inside your event handler, not in Page_Load().
And you don't need to use Page_PreRender.

-Oleg.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top