hidden field

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004.

  1. Hi,

    I need to read an hidden field on the server side (code behind). I can
    modify the value in Javascript (client side), then call "form.submit();" on
    the client side. However, on the server side the value is empty. Any idea on
    the best way to set a hidden field on the client side and read its value on
    the server side?

    Thanks.
    Mike
     
    =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004
    #1
    1. Advertising

  2. Add a runat="server" attribute to your input tag. Like
    this:
    <INPUT type="hidden" id="MyHiddenField" runat="server">
    The runat="server" attribute enables you to access the
    field from your code-behind class. Like this:
    HtmlInputHidden hidden=(HtmlInputHidden) Page.FindControl
    ("MyHidden");

    Regards,
    Anders Norås - blog:
    http://dotnetjunkies.com/weblog/anoras
    >-----Original Message-----
    >
    >Hi,
    >
    >I need to read an hidden field on the server side (code

    behind). I can
    >modify the value in Javascript (client side), then

    call "form.submit();" on
    >the client side. However, on the server side the value

    is empty. Any idea on
    >the best way to set a hidden field on the client side

    and read its value on
    >the server side?
    >
    >Thanks.
    >Mike
    >
    >
    >.
    >
     
    =?iso-8859-1?Q?Anders_Nor=E5s?=, Nov 18, 2004
    #2
    1. Advertising

  3. It did not work. I still have an empty "value". Here is the code I have that
    triggers the form submittal:

    this.MyButton.Attributes["onclick"] =
    "javascript:FromControl.value=\"MyButton\"; __doPostBack('','');";

    I also tried with "form.submit()" in javascript, but the value is alway
    empty. Any suggestion?

    Thanks.
    Mike




    "Anders Norås" wrote:

    > Add a runat="server" attribute to your input tag. Like
    > this:
    > <INPUT type="hidden" id="MyHiddenField" runat="server">
    > The runat="server" attribute enables you to access the
    > field from your code-behind class. Like this:
    > HtmlInputHidden hidden=(HtmlInputHidden) Page.FindControl
    > ("MyHidden");
    >
    > Regards,
    > Anders Norås - blog:
    > http://dotnetjunkies.com/weblog/anoras
    > >-----Original Message-----
    > >
    > >Hi,
    > >
    > >I need to read an hidden field on the server side (code

    > behind). I can
    > >modify the value in Javascript (client side), then

    > call "form.submit();" on
    > >the client side. However, on the server side the value

    > is empty. Any idea on
    > >the best way to set a hidden field on the client side

    > and read its value on
    > >the server side?
    > >
    > >Thanks.
    > >Mike
    > >
    > >
    > >.
    > >

    >
     
    =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004
    #3
  4. Mike,

    runat=server is good enough. After this you get on the server what you set
    on the client. If you are getting empty, it must for the reason you are
    setting empty. Check your client code. Are you sure FromControl is found?
    You might have to write document.getElementById("FromControl").

    Eliyahu

    "Mike" <> wrote in message
    news:...
    >
    > It did not work. I still have an empty "value". Here is the code I have

    that
    > triggers the form submittal:
    >
    > this.MyButton.Attributes["onclick"] =
    > "javascript:FromControl.value=\"MyButton\"; __doPostBack('','');";
    >
    > I also tried with "form.submit()" in javascript, but the value is alway
    > empty. Any suggestion?
    >
    > Thanks.
    > Mike
    >
    >
    >
    >
    > "Anders Norås" wrote:
    >
    > > Add a runat="server" attribute to your input tag. Like
    > > this:
    > > <INPUT type="hidden" id="MyHiddenField" runat="server">
    > > The runat="server" attribute enables you to access the
    > > field from your code-behind class. Like this:
    > > HtmlInputHidden hidden=(HtmlInputHidden) Page.FindControl
    > > ("MyHidden");
    > >
    > > Regards,
    > > Anders Norås - blog:
    > > http://dotnetjunkies.com/weblog/anoras
    > > >-----Original Message-----
    > > >
    > > >Hi,
    > > >
    > > >I need to read an hidden field on the server side (code

    > > behind). I can
    > > >modify the value in Javascript (client side), then

    > > call "form.submit();" on
    > > >the client side. However, on the server side the value

    > > is empty. Any idea on
    > > >the best way to set a hidden field on the client side

    > > and read its value on
    > > >the server side?
    > > >
    > > >Thanks.
    > > >Mike
    > > >
    > > >
    > > >.
    > > >

    > >
     
    Eliyahu Goldin, Nov 18, 2004
    #4
  5. Hi Eliyahu,

    I found the problem. I have nested forms in my page and the hidden control
    was not in the form. Although the javascript did work, the value was not
    posted back.

    Thanks everyone!
    Mike




    "Eliyahu Goldin" wrote:

    > Mike,
    >
    > runat=server is good enough. After this you get on the server what you set
    > on the client. If you are getting empty, it must for the reason you are
    > setting empty. Check your client code. Are you sure FromControl is found?
    > You might have to write document.getElementById("FromControl").
    >
    > Eliyahu
    >
    > "Mike" <> wrote in message
    > news:...
    > >
    > > It did not work. I still have an empty "value". Here is the code I have

    > that
    > > triggers the form submittal:
    > >
    > > this.MyButton.Attributes["onclick"] =
    > > "javascript:FromControl.value=\"MyButton\"; __doPostBack('','');";
    > >
    > > I also tried with "form.submit()" in javascript, but the value is alway
    > > empty. Any suggestion?
    > >
    > > Thanks.
    > > Mike
    > >
    > >
    > >
    > >
    > > "Anders Norås" wrote:
    > >
    > > > Add a runat="server" attribute to your input tag. Like
    > > > this:
    > > > <INPUT type="hidden" id="MyHiddenField" runat="server">
    > > > The runat="server" attribute enables you to access the
    > > > field from your code-behind class. Like this:
    > > > HtmlInputHidden hidden=(HtmlInputHidden) Page.FindControl
    > > > ("MyHidden");
    > > >
    > > > Regards,
    > > > Anders Norås - blog:
    > > > http://dotnetjunkies.com/weblog/anoras
    > > > >-----Original Message-----
    > > > >
    > > > >Hi,
    > > > >
    > > > >I need to read an hidden field on the server side (code
    > > > behind). I can
    > > > >modify the value in Javascript (client side), then
    > > > call "form.submit();" on
    > > > >the client side. However, on the server side the value
    > > > is empty. Any idea on
    > > > >the best way to set a hidden field on the client side
    > > > and read its value on
    > > > >the server side?
    > > > >
    > > > >Thanks.
    > > > >Mike
    > > > >
    > > > >
    > > > >.
    > > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?TWlrZQ==?=, Nov 18, 2004
    #5
    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. Rick
    Replies:
    3
    Views:
    8,199
    Alexey Smirnov
    Apr 13, 2010
  2. GavMc
    Replies:
    4
    Views:
    342
    Evertjan.
    Sep 22, 2005
  3. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    199
  4. Roy Adams
    Replies:
    3
    Views:
    270
    Dr John Stockton
    Dec 21, 2004
  5. Sound
    Replies:
    2
    Views:
    454
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page