How to set the value of a hidden input field to the value stored in a session variable

Last post 06-08-2009 5:55 PM by SuperflyMF. 4 replies.

Sort Posts:

  • How to set the value of a hidden input field to the value stored in a session variable

    06-08-2009, 1:04 PM
    • Member
      8 point Member
    • SuperflyMF
    • Member since 05-29-2009, 11:54 PM
    • Posts 24

    I have a page on my website that is used to get information from my user and then submit this information to a different website.  The fields that the user enters data into are 'input' fields.  In addition to the information that the user enters, I need to be able to include additional information.  This additional information is contained in a 'session' variable.  I have included a hidden input field on my form to accomodate this additional information but I do not know how to set the value of this hidden input field to the session variable.

     

  • Re: How to set the value of a hidden input field to the value stored in a session variable

    06-08-2009, 1:40 PM

     HiddenField1.Value = Convert.ToString(Session["somexyzyoustoredinto"]);

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: How to set the value of a hidden input field to the value stored in a session variable

    06-08-2009, 2:43 PM
    • Member
      8 point Member
    • SuperflyMF
    • Member since 05-29-2009, 11:54 PM
    • Posts 24

    This is the line of code that defines the 'input' field that I am trying to set to the value of a session variable.

    <input type="hidden" name="quantity" type="text" class="formbox" id="quanity" size="10"></span></td>

    The problem seems to be that I cannot set a value into an object that is "class='formbox'.  If I create a 'textbox' to hold my value then I can set the value to a session variable but I do not know how to define an object that is an 'input' and uses a textbox.  My object has to be an input object or it will not be included in the 'submit'.

  • Re: How to set the value of a hidden input field to the value stored in a session variable

    06-08-2009, 2:52 PM
    Answer

     give runat="server" attribute to that hidden control.

    now you can access it in code-behind page.

    then you can set session by

    quanity.Value = Session["yoursessionname"].ToString();

    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever.
  • Re: How to set the value of a hidden input field to the value stored in a session variable

    06-08-2009, 5:55 PM
    • Member
      8 point Member
    • SuperflyMF
    • Member since 05-29-2009, 11:54 PM
    • Posts 24

    That solved the problem.  Thanks again.

Page 1 of 1 (5 items)