Reputation: 3386
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.
Upvotes: 7
Views: 16534
Reputation: 148110
You can access the form control without having runat="server"
you need to do following
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"];
}
Upvotes: 3
Reputation: 14382
HttpContext.Current.Request.Form["foo"]
//Gets the input field with name foo
HttpContext.Current.Request.Files["foo"]
//Gets the dynamically added input type='file'
Upvotes: 0
Reputation: 5727
By using Request.Form["id"]` on Button_Click, you will get the value of html control
string id = Request.Form["id"]
Upvotes: 6
Reputation: 14926
You can try this
get a text area.
In Head use a java script function.
<script type="text/javascript">
function getvalue(temp) {
var imgcontrol = document.getElementById(temp);
alert(imgcontrol.value);
}
</script>
If you want to use in code behind so just take a value in hidden field & access it. in alert you will get value.I hope it help you.
Thanks
Upvotes: 0
Reputation: 21366
You can use ajax post to post your data from the client to the server code . You need to write a web method in asp.net page and user ajax post . here is an example
http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Upvotes: 1