hidden field

G

Guest

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?=

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
 
G

Guest

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
 
E

Eliyahu Goldin

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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top