Hidden Form Field Value Get?

Discussion in 'ASP .Net' started by xenophon, Dec 9, 2005.

  1. xenophon

    xenophon Guest

    I add a Hidden form field to my asp.net page in the codebehind, the
    Value peoperty is set to 0 and EnableViewState is set to true. Then I
    add a LiteralControl with JavaScript that says to set the value to 1.
    If I set view the value of th ehidden form field in the debugger
    during the course of a PostBack, the value is still set to 0.

    Are there any samples of setting a vlaue with JavaScript and reading
    the new value in ASP.NET?

    Thanks.
     
    xenophon, Dec 9, 2005
    #1
    1. Advertising

  2. xenophon

    Jeff Guest

    Make sure that in your ASPX code that you include runat="server" in your
    Hidden form field declaration, like this:
    <input id="myHiddenField" type=hidden value="" runat="server">

    Then declare it in the code-behind like this:
    protected System.Web.UI.HtmlControls.HtmlInputHidden myHiddenField;


    Then you can read the value like this (in code-behind):
    string hiddenValue = myHiddenField.Value

    or set the value like this (in code-behind):
    myHiddenField.Value = "whatever";

    And client-side you just refer to the hidden field like you normally would:
    document.Form1.myHiddenField.value = "whatever";

    -HTH

    "xenophon" <> wrote in message
    news:...
    >
    > I add a Hidden form field to my asp.net page in the codebehind, the
    > Value peoperty is set to 0 and EnableViewState is set to true. Then I
    > add a LiteralControl with JavaScript that says to set the value to 1.
    > If I set view the value of th ehidden form field in the debugger
    > during the course of a PostBack, the value is still set to 0.
    >
    > Are there any samples of setting a vlaue with JavaScript and reading
    > the new value in ASP.NET?
    >
    > Thanks.
    >
     
    Jeff, Dec 10, 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. xenophon
    Replies:
    2
    Views:
    965
    Steven Cheng[MSFT]
    Dec 21, 2005
  2. David Jia
    Replies:
    5
    Views:
    620
    Mark Rae
    Oct 16, 2006
  3. Rick
    Replies:
    3
    Views:
    8,216
    Alexey Smirnov
    Apr 13, 2010
  4. GavMc
    Replies:
    4
    Views:
    350
    Evertjan.
    Sep 22, 2005
  5. Replies:
    6
    Views:
    209
Loading...

Share This Page