How to maintain the value of label after postback in Asp.net? [closed]

回眸只為那壹抹淺笑 提交于 2019-11-28 12:32:46
Adil

The label is converted into a span element and the html elements, like span or div, do not have ViewState. Neither the text or html of these is sent server side like form elements.

Form elements that are posted are the input elements as well as hidden fields. ASP.net maintains ViewState using hidden field and input elements.

I am afraid you have to use hidden fields to maintain the value of labels between postbacks.

HTML

<input id="hdnLabelState" type="hidden" runat="server" >

Javascript

document.getElementById('<%= hdnLabelState.ClientID %>').value = "changed value of span";

Server side (code behind)

string changedLabelValue = hdnLabelState.Value;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!