Please explain strange viewstate behavior...

Discussion in 'ASP .Net' started by =?Utf-8?B?cmdyYW5kaWRpZXI=?=, Oct 26, 2005.

  1. I am dynamically adding an HtmlInputHidden element with different values.
    The problem is the first time I add it with a given value and submit it then
    change the value within the Page_Load event it still has the original value.
    I am guessing this has something to do with viewstate. I have turned off
    viewstate at the page level, but the issue still occurs. Any suggestions?

    The code is basic:
    HtmlInputHidden phihAction = new HtmlInputHidden();

    phihAction.ID = "hdnAction";
    phihAction.Value = ((short)pactAction).ToString();
    mfrmUser.Controls.Add( phihAction );

    pactAction is an enumeration that changes based on action (i.e. 1=Add, 2=Edit)

    Any help in understanding why it does what it does and how to work around it
    would be greatly appreciated.

    --
    Robert
     
    =?Utf-8?B?cmdyYW5kaWRpZXI=?=, Oct 26, 2005
    #1
    1. Advertising

  2. Robert,

    You need to check IsPostBack property befory assigning the value:

    HtmlInputHidden phihAction = new HtmlInputHidden();

    phihAction.ID = "hdnAction";
    if (IsPostBack)
    phihAction.Value = ((short)pactAction).ToString();
    mfrmUser.Controls.Add( phihAction );

    Eliyahu

    "rgrandidier" <> wrote in message
    news:...
    > I am dynamically adding an HtmlInputHidden element with different values.
    > The problem is the first time I add it with a given value and submit it

    then
    > change the value within the Page_Load event it still has the original

    value.
    > I am guessing this has something to do with viewstate. I have turned off
    > viewstate at the page level, but the issue still occurs. Any suggestions?
    >
    > The code is basic:
    > HtmlInputHidden phihAction = new HtmlInputHidden();
    >
    > phihAction.ID = "hdnAction";
    > phihAction.Value = ((short)pactAction).ToString();
    > mfrmUser.Controls.Add( phihAction );
    >
    > pactAction is an enumeration that changes based on action (i.e. 1=Add,

    2=Edit)
    >
    > Any help in understanding why it does what it does and how to work around

    it
    > would be greatly appreciated.
    >
    > --
    > Robert
     
    Eliyahu Goldin, Oct 27, 2005
    #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. Christopher Richards

    Can't explain this strange behavior

    Christopher Richards, Feb 15, 2005, in forum: HTML
    Replies:
    3
    Views:
    425
    Travis Newbury
    Feb 15, 2005
  2. REH
    Replies:
    25
    Views:
    857
    Victor Bazarov
    Mar 29, 2005
  3. Replies:
    4
    Views:
    375
    Roland Pibinger
    Nov 10, 2006
  4. Train Bwister
    Replies:
    1
    Views:
    298
    Diez B. Roggisch
    Apr 30, 2009
  5. BKDotCom
    Replies:
    3
    Views:
    90
    Jonas Raoni
    Dec 22, 2005
Loading...

Share This Page