Conditionally disable html control?

J

Jens Weiermann

Hi,

I need to conditionally disable a html (not web forms) button control. The
condition is to be evaluated server-side. What is the smartest way to do
this?
I'm now using a literal server-side control, conditionally placing the
complete html code into the text property a lá

If (SomeCondition)
literal1.Text = "<INPUT type=\"button\" value=\"Something\">";
else
literal1.Text = "<INPUT type=\"button\" value=\"Something\" disabled>";

My guess would be that there is a smarter way to do this... Right?

Thanks!
Jens
 
E

Eliyahu Goldin

Jens,

You can access any html control on server side if you specify
runat="server".

In your case:

In the .aspx file:
<INPUT runat="server" id="myButton" type="button" value="Something">

In the code:
myButton.Disabled=false;

myButton will automatically get type HtmlInputButton.

Eliyahu
 
J

Jens Weiermann

Eliyahu said:
You can access any html control on server side if you specify
runat="server". [SNIP]
myButton will automatically get type HtmlInputButton.

thanks - that does the trick! Didn't know this was possible!

Jens
 

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,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top