当我们使用文字创建控件时如何查找控件

发布于 2024-09-29 17:19:13 字数 487 浏览 0 评论 0原文

我正在使用一个面板,然后在其中创建一个文字,而不是我创建的:

string temp ="
<input type="checkbox" id="forum0">
<input type="checkbox" id="forum1">
<input type="checkbox" id="forum2">
<input type="checkbox" id="forum3">
<input type="checkbox" id="forum4">
<input type="checkbox" id="forum5">
" ...

然后将这个字符串分配给

literal.text=temp;

现在,如果我想找到 id=forum0 的复选框,我会这样做吗?我正在使用 findcontrol 我几乎使用了所有东西请举例说明。

谢谢

I am using a panel and then I create a literal in it, than I create :

string temp ="
<input type="checkbox" id="forum0">
<input type="checkbox" id="forum1">
<input type="checkbox" id="forum2">
<input type="checkbox" id="forum3">
<input type="checkbox" id="forum4">
<input type="checkbox" id="forum5">
" ...

and then assign this sting to

literal.text=temp;

now if i want to find the checkbox with id=forum0 ho do i do that i am using findcontrol i have used almost everything kindly help with example.

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放赐 2024-10-06 17:19:13

如果您使用文字控件将表单元素添加到表单中,则无法通过 FindControl 方法获取这些控件。因为它们作为静态 html 元素添加到您的页面中。

您有两个选项可以在服务器端访问它们:

  1. 您应该将它们添加为服务器控件。然后您就可以完美地访问它们。
  2. 如果您只想在页面回发时访问它们的值,您可以使用 Request :

    string yourControlsValue = Request["Your_Controls_Name"];

If you're adding form elements to your form by using literal controls, you can't get these controls by FindControl method. Because they're added to your page as static html elements.

You have two options to reach them at server side :

  1. You should add them as server control. Then you can perfectly access them.
  2. If you only want to access their values when your page posts back, you can use Request :

    string yourControlsValue = Request["Your_Controls_Name"];

自找没趣 2024-10-06 17:19:13

ASP.Net 只会实例化在 aspx 页面上找到的控件的控件对象,而不是通过实际呈现的 HTML 传递的控件对象,这是创建复选框的位置。您应该会发现一个名为“forum0”的参数返回到页面处理程序,并且应该可以通过 Request["forum0"] 构造访问该参数。

ASP.Net will only instantiate control objects for the controls found on the aspx page, not that are delivered through the actual rendered HTML, which is where your checkbox is being created. You should find a parameter being returned to the Page handler with the name 'forum0' and that should be accessible through the Request["forum0"] construct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文