我创造了
<input type="checkbox" id="test" >
使用文字。现在我想得到这个控件,这样我就可以检查它是否被选中。如何在 aspx.cs 页面中找到这个控件?
最佳答案
如果你想找到对文件隐藏代码的控制,那么你应该将其设置为 runat="server",
literal.text = "<input type=\"checkbox\" id=\"forum1\" runat=\"server\">";
HtmlInputCheckBox test = (HtmlInputCheckBox) Page.FindControl("test");
但是每当页面要回发时,您都会丢失此控件的状态。
希望这会给你正确的解决方案 http://www.codeasp.net/blogs/SumitArora/microsoft-net/841/value-of-dynamic-textbox-lost-on-postback
可以使用页面初始化事件来生成控件
protected override void OnInit(EventArgs e)
{
HtmlInputCheckbox test = new HtmlInputCheckbox ();
test.id= "test";
pnlControl.Controls.Add(test);
base.OnInit(e);
}
关于asp.net - 查找控件 Asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4051560/