如何在 asp.net 中查看正常 HTML 输入的状态

发布于 2024-11-16 17:33:14 字数 154 浏览 4 评论 0原文

如何在 ASP.net 中的普通 HTML 输入元素中使用 VIEWSTATE。我有一个包含很多输入元素的表单,并且我有正常的(不是 asp.net 输入元素)输入元素。现在我应该维护这些元素的视图状态。

谢谢

How to use VIEWSTATE in normal HTML input elements in ASP.net. I am having a form with lot of input elements and i had normal(not asp.net input elements) input elements. Now i should i maintain viewstate for these elements.

Thank You

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

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

发布评论

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

评论(4

客…行舟 2024-11-23 17:33:14

尝试编写 JavaScript 函数,在回发之前将输入值存储在 asp:HiddenField
并在回发后从中恢复值。

例子:

function post(){
   var viewState = ...; // save input values
   $('#<%= Hidden1.ClientID %>').val(viewState);
   __doPostBack("<%=UniqueID%>");
}

$(function(){
    var viewState = $('#<%= Hidden1.ClientID %>').val();
    //restore input values
});

Try writing javascript function, that store input values in asp:HiddenField before postback
And restore values from it after postback.

Example:

function post(){
   var viewState = ...; // save input values
   $('#<%= Hidden1.ClientID %>').val(viewState);
   __doPostBack("<%=UniqueID%>");
}

$(function(){
    var viewState = $('#<%= Hidden1.ClientID %>').val();
    //restore input values
});
迟月 2024-11-23 17:33:14

普通html元素中还有一个“enableviewstate”属性,只需将其设置为true即可。

There is also a property of "enableviewstate" in normal html elements, just set it to true.

秋千易 2024-11-23 17:33:14

没有理由这样做,因为在回发之后,输入元素再次将值发送到页面,并在回发后再次拥有内容。

这样做的唯一原因是尝试在发布之前获取先前的值后退。

There is not reason to do that because after the post back the input elements post the value again to the page, and have the content again after the post back

The only reason to do that is to try to get the previous values, before the post back.

冧九 2024-11-23 17:33:14

这篇文章发表已经有一段时间了,但这是我的解决方案,对我有用。

只需在 ASP.Net 中为 html 控件设置 runat="server" 属性,而不是隐藏字段。
例如,

<input type="text" runat="server"/>

这将做两件事:

  • 使 html 控件在后面的 ASP.NET 代码中可访问。
  • 自动维护视图状态,除非您显式将 EnableViewState 设置为 false,从而允许页面回发之间保持持久性。

It's been awhile since this post was made, but here's my solution which worked for me.

Instead of hidden fields, just set the runat="server" attribute for your html control in ASP.Net.
E.g.

<input type="text" runat="server"/>

This will do two things:

  • Make the html control accessible in the ASP.NET code behind.
  • Automatically maintain viewstate unless you explicitly set the EnableViewState to be false, allowing for persistence between page postbacks.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文