C# ASP.Net:从 Request.Form 获取隐藏的自定义属性

发布于 2024-09-11 03:05:23 字数 320 浏览 1 评论 0原文

我有一些代码正在渲染隐藏控件的一些自定义属性(没有 runat=server)。

像这样的东西,

我的表单上有很多这样的隐藏元素。

当我提交表单时,我会循环访问一组 id,例如 1200 到 1250,因此我将基于该值读取控件,并使用 Request.Form["hdn "] 隐藏。

现在的问题是,正如我们所知,我们得到了当我们对隐藏执行 Request.Form["id"] 时,表单中的 value 属性,我想从隐藏元素中读取我的自定义属性。有什么办法吗?请注意,我不能在这里触及渲染部分。

谢谢。

吉米.

I have some code which is rendering some custom attributes of Hidden Control (without runat=server).

Something like,

And I have a lot of these hidden elements on my form.

When I submit the form, I am looping through a set of ids, say 1200 to 1250, so I will read controls based on that, and also hidden with Request.Form["hdn "]

Now problem is, as we know we get value attribute from form when we do Request.Form["id"] for hidden, I want to read my custom attributes from hidden element. Is there any way? Note that, I can not touch the rendering part here.

Thanks.

Jimmy.

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

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

发布评论

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

评论(1

仙气飘飘 2024-09-18 03:05:23

我认为这不会起作用 - 如果您正在处理纯 HTML 控件(即没有 runat="server" 属性的控件),那么当它们以表单形式发布时,您得到的只是一堆键值对,对应于元素的 ID 及其值。

当您执行 Request.Form["id"] 时,您没有获取该元素,您只是获取该元素的(即元素的 value 属性)。无法访问任何其他属性(自定义属性或其他属性)的内容。

您需要将 runat="server" 属性添加到这些控件,然后在回发中选取它们,或者使用一些疯狂的 javascript 选取自定义属性值并将它们粘贴到以某种方式形成 id/值集合。

I don't think this is going to work - if you're dealing with plain HTML controls (i.e. ones without the runat="server" attribute), then when they're posted in a form, all you get is a load of key-value pairs, corresponding to elements' IDs and their Values.

When you do Request.Form["id"], you're not getting the element, you're just getting the value of that element (i.e. whatever was in the element's value attribute). There's no way to get access to the contents of any other attributes, custom or otherwise.

You'll either need to add the runat="server" attribute to these controls and then pick them up in a postback, or use some crazy javascript to pick out the custom attribute values and stick them in the form id/value collection somehow.

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