asp.net - 查找控件 Asp.net

标签 asp.net findcontrol

我创造了

<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/

相关文章:

c# - 使 IIS 开始通过 Owin 管道响应请求的过程是什么?

asp.net - FindControl 在 FormView 的错误模板中查找控件

asp.net - 将字节转换为图像 ASP.NET c# 并在 Image1.Url 中使用它

asp.net - ASP.NET-如何找到进程标识?

c# - ASP.NET gridview复选框问题

c# - 如何在c#.net中通过ClientID查找控件?

asp.net - 如何在中继器页眉或页脚中查找控件

c# - RowDataBound-Event 中的 FindControl 以错误结束

asp.net - 关于母版页的问题

asp.net - 无法让我的导航栏以网站 ASP.Net 为中心