problem with hidden field from a custom control in a form

Discussion in 'ASP .Net Web Controls' started by ThunderMusic, Jul 4, 2006.

  1. ThunderMusic

    ThunderMusic Guest

    Hi,
    I have a custom control that draws many thing on the screen including a
    hidden field. This hidden field's value is modified through client code.
    What I want to do is the following : When there is a postback of the page, I
    want this hidden field to keep it's value (from the viewstate or something
    like this). Is there an easy solution? Would you need the code.

    Right now I :
    create a HiddenField in the PreRender of my control
    store it in a member variable
    render it in the RenderBeginTag
    modify it from client-side code
    I want to access it's value in the RenderContents method when there is a
    post back but right now, the value is always blank.

    Is there a solution to my problem? Am I doing the things right and missing a
    little tiny thing?

    Thanks

    ThunderMusic
     
    ThunderMusic, Jul 4, 2006
    #1
    1. Advertising

  2. ThunderMusic

    ThunderMusic Guest

    ok, I found it... I have to create my HiddenField in the OnInit event of
    my control so the viewstate is reloaded correctly between the OnInit and the
    OnLoad of my control.

    Thanks to all

    ThunderMusic

    "ThunderMusic" <> wrote in message
    news:...
    > Hi,
    > I have a custom control that draws many thing on the screen including a
    > hidden field. This hidden field's value is modified through client code.
    > What I want to do is the following : When there is a postback of the page,
    > I want this hidden field to keep it's value (from the viewstate or
    > something like this). Is there an easy solution? Would you need the code.
    >
    > Right now I :
    > create a HiddenField in the PreRender of my control
    > store it in a member variable
    > render it in the RenderBeginTag
    > modify it from client-side code
    > I want to access it's value in the RenderContents method when there is a
    > post back but right now, the value is always blank.
    >
    > Is there a solution to my problem? Am I doing the things right and missing
    > a little tiny thing?
    >
    > Thanks
    >
    > ThunderMusic
    >
     
    ThunderMusic, Jul 4, 2006
    #2
    1. Advertising

  3. ThunderMusic

    Kevin R Guest

    One of the royal pains of of asp.net is that when you are using dynamic
    controls, you have to render them prior to the firing of the postback events
    in order to get the original value. To me this is excess overhead as in many
    cases you may end up drawing controls twice.

    You could do this in the Load event as well.

    "ThunderMusic" wrote:

    > ok, I found it... I have to create my HiddenField in the OnInit event of
    > my control so the viewstate is reloaded correctly between the OnInit and the
    > OnLoad of my control.
    >
    > Thanks to all
    >
    > ThunderMusic
    >
    > "ThunderMusic" <> wrote in message
    > news:...
    > > Hi,
    > > I have a custom control that draws many thing on the screen including a
    > > hidden field. This hidden field's value is modified through client code.
    > > What I want to do is the following : When there is a postback of the page,
    > > I want this hidden field to keep it's value (from the viewstate or
    > > something like this). Is there an easy solution? Would you need the code.
    > >
    > > Right now I :
    > > create a HiddenField in the PreRender of my control
    > > store it in a member variable
    > > render it in the RenderBeginTag
    > > modify it from client-side code
    > > I want to access it's value in the RenderContents method when there is a
    > > post back but right now, the value is always blank.
    > >
    > > Is there a solution to my problem? Am I doing the things right and missing
    > > a little tiny thing?
    > >
    > > Thanks
    > >
    > > ThunderMusic
    > >

    >
    >
    >
     
    Kevin R, Jul 4, 2006
    #3
  4. ThunderMusic

    Guest

    Do you mean to say that dynamic controls need to be recreated (not
    rendered) and added back to the page control tree before the postback
    events are handled?

    Kevin R wrote:
    > One of the royal pains of of asp.net is that when you are using dynamic
    > controls, you have to render them prior to the firing of the postback events
    > in order to get the original value. To me this is excess overhead as in many
    > cases you may end up drawing controls twice.
    >
    > You could do this in the Load event as well.
    >
    > "ThunderMusic" wrote:
    >
    > > ok, I found it... I have to create my HiddenField in the OnInit event of
    > > my control so the viewstate is reloaded correctly between the OnInit and the
    > > OnLoad of my control.
    > >
    > > Thanks to all
    > >
    > > ThunderMusic
    > >
    > > "ThunderMusic" <> wrote in message
    > > news:...
    > > > Hi,
    > > > I have a custom control that draws many thing on the screen including a
    > > > hidden field. This hidden field's value is modified through client code.
    > > > What I want to do is the following : When there is a postback of the page,
    > > > I want this hidden field to keep it's value (from the viewstate or
    > > > something like this). Is there an easy solution? Would you need the code.
    > > >
    > > > Right now I :
    > > > create a HiddenField in the PreRender of my control
    > > > store it in a member variable
    > > > render it in the RenderBeginTag
    > > > modify it from client-side code
    > > > I want to access it's value in the RenderContents method when there is a
    > > > post back but right now, the value is always blank.
    > > >
    > > > Is there a solution to my problem? Am I doing the things right and missing
    > > > a little tiny thing?
    > > >
    > > > Thanks
    > > >
    > > > ThunderMusic
    > > >

    > >
    > >
    > >
     
    , Jul 6, 2006
    #4
    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. ThunderMusic
    Replies:
    3
    Views:
    506
  2. Rick
    Replies:
    3
    Views:
    8,597
    Alexey Smirnov
    Apr 13, 2010
  3. GavMc
    Replies:
    4
    Views:
    383
    Evertjan.
    Sep 22, 2005
  4. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    224
  5. Roy Adams
    Replies:
    3
    Views:
    292
    Dr John Stockton
    Dec 21, 2004
Loading...

Share This Page