c# - Why label's value is changed? -


i know if viewstate disabled textbox, not losing data because implements ipostbackdatahandler interface.

<asp:textbox id="textbox1" runat="server" enableviewstate="false"/> 

but question why happens label too? why label not losing it's data if viewstate disabled since label doesn't implements ipostbackdatahandler interface?

<asp:label id="label1" runat="server" enableviewstate="false" viewstatemode="disabled"/> 

textbox definition:

public class textbox : webcontrol, ipostbackdatahandler, 

label definition:

public class label : webcontrol, itextcontrol 

my code:

<form id="form1" runat="server"> <div>     <asp:label id="label1" runat="server" enableviewstate="false" viewstatemode="disabled" text="before click"></asp:label>     <asp:textbox id="textbox1" runat="server" enableviewstate="false"></asp:textbox>     <asp:button id="button1" runat="server" text="button" onclick="button1_onclick"/> </div> </form> 

and code behind:

protected void button1_onclick(object sender, eventargs e) {     label1.text = "changed."; } 

i expected see "before click" in label after clicked button see "changed" text in label after clicked button.

upd:

i think have wrong understanding viewstate is.

data in viewstate being stored between requests, not during page lifecycle. btw - viewstate data generated after prerendercomplete event in savestatecomplete event.

https://msdn.microsoft.com/en-us/library/ms178472.aspx

if have viewstate switched off - think not generated in output.

during page lifecycle data assigned controls(and page fields , properties, page class) rendered defined in aspx. lost after, unless saved in viewstate.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -