Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read HTML Elements from Code Behind using asp.net C#

Tags:

c#

asp.net

How can I read a HTML Element like input type=checkbox from the code behind? Without adding runat="server". Is that possible?

like image 568
Jepe d Hepe Avatar asked Jan 24 '23 00:01

Jepe d Hepe


1 Answers

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:

  • If user checked the element, then you will get "Yes" in the postedValue.
  • Otherwise postedValue will be null.
like image 142
Dmytrii Nagirniak Avatar answered Jan 31 '23 22:01

Dmytrii Nagirniak