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

Here I have javascript to add html control (Input). I cannot apply asp.net control here because it is dynamically included in a java script I just want to use the input value in my code behind the page that javascript is dynamically generated.

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

+6
source share
5 answers

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

string id = Request.Form["id"]

+4
source

You can access the control without having runat="server" , which you need to execute

  • The form method must be of type POST.
  • The tag must have the attribute NAME. Because it is used as a key in the form of [].
  • The Html control must have access in code.

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"]; } 
+2
source

You can use the ajax post to send your data from the client to the server code. You need to write a web method on the asp.net page and in the ajax user post. here is an example

http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

+1
source

You can try this

get the text area.

In Head, use the java script function.

 <script type="text/javascript"> function getvalue(temp) { var imgcontrol = document.getElementById(temp); alert(imgcontrol.value); } </script> 

If you want to use the code in the code, just use the value in the hidden field and get access to it. in the warning you get the value. I hope this helps you.

thanks

0
source
 HttpContext.Current.Request.Form["foo"] //Gets the input field with name foo HttpContext.Current.Request.Files["foo"] //Gets the dynamically added input type='file' 
0
source

Source: https://habr.com/ru/post/889195/


All Articles