开发者

How to viewstate in normal HTML input in asp.net

开发者 https://www.devze.com 2023-03-14 09:36 出处:网络
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 viewst

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.

T开发者_如何学Pythonhank You


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
});


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


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.


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消