Should I use the PreRender event

Discussion in 'ASP .Net Building Controls' started by STom, Sep 28, 2003.

  1. STom

    STom Guest

    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
    STom, Sep 28, 2003
    #1
    1. Advertising

  2. STom

    Oleg Ogurok Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    Oleg Ogurok, Sep 29, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxpcmV6YSBaaWFp?=

    PreRender Event occurs immediatley after Load event

    =?Utf-8?B?QWxpcmV6YSBaaWFp?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,097
    Hans Kesting
    Feb 9, 2004
  2. DalePres
    Replies:
    1
    Views:
    2,823
    Natty Gur
    May 13, 2004
  3. wardy

    begin prerender event

    wardy, Jun 8, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    509
    wardy
    Jun 8, 2004
  4. wardy
    Replies:
    6
    Views:
    7,079
    John Saunders
    Jun 18, 2004
  5. Jimmy
    Replies:
    5
    Views:
    15,219
    =?Utf-8?B?Sm9yZ2UgTCBNYXRvcyBbTUNTRC5ORVRd?=
    Apr 27, 2005
Loading...

Share This Page