Is there a Server Side hidden input?

D

Dan

Is there a way to access and set a hidden input types in the code-behind
page for ASP.Net?

This seems like a common thing that would need to be done, I must be missing
something obvious.

Basically, I need to have some sort of server side hidden input type
component which I can set in the code behind page, and also be used in
javascript.

Thanks in advance,
Dan
 
C

Chad Z. Hower aka Kudzu

Dan said:
Is there a way to access and set a hidden input types in the code-behind
page for ASP.Net?

You can edit the HTML directly to enter them. But you want to modify them
directly in server side code too?

Check the WebForm properties for options. That failing, a really simple
custom control that does this would only be a few lines if you dont need
design time support.
 
S

Scott M.

You could use a server label with its visibility set to false, which results
in an HTML <SPAN> tag with the visibility:false value for the style
attribute.
 
A

Alphonse Giambrone

Just use an html hidden input and add runat="server". If you are using VS,
you can right click on the control and check run as server control.
 
D

Dan

Thanks for the response.

You mean there is no built-in hidden server control?

That seems like a pretty striking oversight. Suppose I have some value that
I want to use in a javascript calculation but doesn't need to be displayed,
so I want to put it in a hidden input field. How would I set this from the
code-behind page?

I guess I can generate the HTML for the <input> tag each time but then I
lose the state management that the other server-side components have.

Just seems like a simple thing Microsoft should have included. They have all
the other input types, why not have a hidden one?

Thanks,
Dan
 
D

Dan Brussee

I believe you can add the "runat=server" magic text on a hidden input
tag. At that point, you can code it like any other tag and have the
value available on server side. You would need to use the attributes
collection instead of a "text" property I think


Thanks for the response.

You mean there is no built-in hidden server control?

That seems like a pretty striking oversight. Suppose I have some value that
I want to use in a javascript calculation but doesn't need to be displayed,
so I want to put it in a hidden input field. How would I set this from the
code-behind page?

I guess I can generate the HTML for the <input> tag each time but then I
lose the state management that the other server-side components have.

Just seems like a simple thing Microsoft should have included. They have all
the other input types, why not have a hidden one?

Thanks,
Dan
 
S

Scott M.

You would use its VALUE attribute as always.


Dan Brussee said:
I believe you can add the "runat=server" magic text on a hidden input
tag. At that point, you can code it like any other tag and have the
value available on server side. You would need to use the attributes
collection instead of a "text" property I think
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top