找到控制和HTML标记 [英] find control and html tags
本文介绍了找到控制和HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个code在我的默认aspx文件:
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>
和我的code后面的是:
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);
我的问题是这里的FindControl(TXT)返回空值!因为我用&LT;输入&GT;
,我怎么可以处理这个控制
my problem is here that findcontrol ("txt") return null value!!! because i used <input>
,how can i handle this control ?
推荐答案
首先,你不需要 holder1.FindControl
,你可以直接访问控制。
Firstly, you don't need the holder1.FindControl
as you can access the controls directly.
要获得输入
控件,使用code;
To get the input
control, use the code;
HtmlInputText tb1 = this.txt;
Response.Write(tb1.Value);
您可能需要导入System.Web.UI.HtmlControls。
You might need to import System.Web.UI.HtmlControls.
Using System.Web.UI.HtmlControls;
修改
要找到已通过JavaScript被动态添加控件,您需要使用请求
对象。
To find controls which have been dynamically added via Javascript, you will need to use the Request
object.
string theValue = Request.Form["txt"].ToString();
这篇关于找到控制和HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文