How to maintain a value assigned to a label through javascript after postback?
Problem: I have assigned a label value using a clientside function. But whenever postback happened, label values are gone.
Solution i found: After searching a lot, all are suggessting to store and retrieve the value to & from a hidden field.
Note: But i want to achieve this without using hidden field as it may
increase pageload time.
The state of label
is not maintained in ViewState
by asp.net. The labels are converted in to spans and the html of span is not posted on submitting form, this is why changes made by client are not persisted. You can put the state of label in some hidden field when you change it in javascript and access it on server.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With