HighTechTalks DotNet Forums  

Should I use the PreRender event

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Should I use the PreRender event in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
STom
 
Posts: n/a

Default Should I use the PreRender event - 09-28-2003 , 07:06 AM






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



Reply With Quote
  #2  
Old   
Oleg Ogurok
 
Posts: n/a

Default Re: Should I use the PreRender event - 09-29-2003 , 04:37 PM







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.

"STom" <stombiztalker (AT) hotmail (DOT) com> wrote

Quote:
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





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.