Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access html control value in code behind without using runat server?

Here I have using javascript for adding html control(Input). here I am not able to apply asp.net control because it come dynamically from java script I just want to use input value in my coed behind page which is generated by javascript dynamically.

Is there any way to get value from HTML control in asp.net.

like image 621
Yashwant Kumar Sahu Avatar asked May 27 '11 09:05

Yashwant Kumar Sahu


2 Answers

By using Request.Form["id"]` on Button_Click, you will get the value of html control

string id = Request.Form["id"]

like image 50
Saurabh Avatar answered Sep 19 '22 17:09

Saurabh


You can access the form control without having runat="server" you need to do following

  • The form method should be of type POST.
  • The tag should have an attribute called NAME. Because it is used as key in form[].
  • Html control should be access in code behind.

Html

<form id="form1" runat="server" >   
    <input type="text" name="txtName" value="hidden text" />
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />   
</form>

C# Code:

protected void Button1_Click(object sender, EventArgs e)
{
    string s = Page.Request.Form["txtName"];
}
like image 29
Adil Avatar answered Sep 17 '22 17:09

Adil