Find control from html to c# in asp.net [closed]
I have problem that how to get html control id in c# code behind page.?? thanks in advance......
If your control is declared in the markup (like <asp:Label ID="myLabel" runat="server"/>
) you can just use autogenerated myLabel
property in code behind. Otherwise, if the control is created dynamically or declared in a template (for example within Repeater
) you need to know its parent container and do container.FindControl("controlID")
.
If You have input html control and wish to access its value You can get this on lage load using Page.Request.Params property:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.params.aspx
Or if You wish to access it fully (for read/write) You have to add runat=server attribute and then (for asp.net 3.5)
http://www.w3schools.com/aspnet/aspnet_refhtmlcontrols.asp
Here You go: aspx:
<form id="form1" runat="server">
<div>
<input type="text" runat="server" id="htmlText" name="htmlText"/>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
cs:
...
protected void Page_Load(object sender, EventArgs e) {
htmlText.Value = "kuku";
}
...
精彩评论