Reputation: 909
How can I read a HTML Element like input type=checkbox from the code behind? Without adding runat="server"
. Is that possible?
Upvotes: 4
Views: 18986
Reputation: 24078
How can i read a HTML Element like input type=checkbox from the code behind?
Before asking this you should first understand that HTML Elements have nothing to do with the code-behind (on the server).
You cannot access them in any way as you cannot access the client's browser from the server.
If you want to access THE VALUE of the INPUT element that is posted to the server then you should use:
var postedValue = Request.Form["nameOfElement"];
So if you have HTML:
<input type="check" name="nameOfElement" value="Yes" />
then:
postedValue
.postedValue
will be null.Upvotes: 6
Reputation: 2086
Look in the Request.Form collection to retrive those values
something along the lines of checking for this condition:
Request.Form("Name") != null
to check if the checkbox of name "Name" is checked. If the box isn't checked that value will be null
Upvotes: 3