简体   繁体   中英

Rookie questions for ViewState and Html Control

I just get start to learn about ASP.Net. I try to figure out the principle of page process. And I get some questions about ViewState and Html Control.

<input type="text" id="FirstName" />
<br />
<input type="text" id="LastName" runat="server" />

Here is my HTML. I filled two text box, and click submit. The control that running at server kept the value and the other did not.

I check the class HtmlInputText, and find it implemented the interface IPostBackDataHandler, so it will not influenced by ViewState? (I know it through someone`s blog, is that right?)

My idea about ViewState is the one that keep the changing message of every control. The controls in page will be initialized according the default settings and ViewState.

But I still can`t figure out something : Does ViewState keep the changing message of "FirstName"? The Web Control just like or the HTML Control running at server, they all implemented the interface IPostBackDataHandler, so the ViewState is useless?

Please help me to understand the use of ViewState or something... (I messed up...)

A ViewPage inherits from the Page class. So it's a "WebForm", and it has a code-behind, so you can basicaly request the page directly. If you use a control that will perform a normal postback, a postback will take place, in this case you have added the WebForm behavior, this is not what we shoulde do (mix them both), you should make sure an action method of the Controller is executed instead. There will be some controls in the final version that will instead of doing a "postback", make sure an Action method will be excuted. You can't access the ViewState from the Controller so in that way it will not on a controller level. If you have a control that uses ViewState, and press on a "button" or "Link" which will make sure a Action method is executed, the ViewState will not be posted and in that case when the controls will get data form the ViewState it's empty. So the controls will not work if they need ViewState.

Hope this helps source:< Link >

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM