i have this code in my default aspx file :
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="holder1" runat="server">
<asp:Label ID="label1" runat="server" Text="Label">
</asp:Label>
<input type="text" ID="txt" runat="server"/>
<asp:TextBox ID="txt2" runat="server"></asp:TextBox>
<asp:Button Text="Ok" ID="btnOk" runat="server" onclick="btnOk_Click" />
</asp:PlaceHolder>
</div>
</form>
</body>
and my code behind is :
TextBox tb1 = holder1.FindControl("txt") as TextBox;
Response.Write(tb1.Text);
TextBox tb2 = holder1.FindControl("txt2") as TextBox;
Response.Write(tb2.Text);
my problem is here that findcontrol (“txt”) return null value!!! because i used <input> ,how can i handle this control ?
Firstly, you don’t need the
holder1.FindControlas you can access the controls directly.To get the
inputcontrol, use the code;You might need to import System.Web.UI.HtmlControls.
Edit
To find controls which have been dynamically added via Javascript, you will need to use the
Requestobject.