问题
I am changing an asp.net label control's text using jquery at the client. But when I read it at the webserver ( C# code ), it shows me the value that was set in the UI (aspx). Is label text not a part of the control state?
Is there a way to force the label to be a part of the control state (the viewstate contains the values of the other controls like the textbox) ?
回答1:
Labels do not post their value back to the webserver. A label is basically span or label tag.
You have to either store the change in a hidden textbox as well as in the label
or
Make a textbox appear like a label in styling so the value posts back.
回答2:
Did you try EnableViewState = true for this control?
Also - IMO - the label values are not part of the posted form collection items.
Why don't you put a hidden field on the form which contains the changed text from the label & then read it on the server side?
来源:https://stackoverflow.com/questions/10324631/asp-net-label-text-changed-at-the-client-is-not-available-at-the-web-server-end