So, having discussed all of that, let us just click Step Over and see what happens when the HTML does indeed get sent back to the user. So, let us take a look at the HTML and take some of that theory and put it into some practice, view source. I am going to maximize this window.
Okay, so most of this page is fairly straightforward. There are one or two ‘startling’ exceptions to that rule. Obviously the first item you need to look at is the hidden field here. This input field is a hidden field and this is the view state field. This is the civilized state of the asp.net web controls as they have currently being sent back from asp.net to the client. So, this acts if you like as a memory of what asp.net thinks as the state of the web page that it sent back to us. So, that is one input control and then there is another input control here which is the NameTexbox. We have another control which specifies the list of items that the user can select from. So, that is the third input control if you like. And then we have two buttons here which represent “This Year” or “Last year” events depending on which button we click. Either this input field or that input field will be posted back to our asp.net application. So, we can think of these two as being a single piece of information effectively and then finally at the bottom we have another hidden input field which is not clearly associated with event validation.
Now, we are not going to talk about validation here but we are going to talk about it in the next lesson. So, we ignore this event of mechanism for validation at this stage. Okay, so let us close the view source and actually enter some data on this webpage. So, we will enter a name, Joseph and let us Joseph has visited Germany and France and let me click this button. Now, when we click this button, it is going to post data back to our web server. In fact, it is going to post five pieces of data as we have just looked at and I am going to prove that point in the moment. So, let us click the button. Okay and that takes us back to our web page. And at this stage the process is a little bit more complicated and I am going to explain exactly how the page is re-initialized and how the view state comes into play at this stage.
Okay, so let us just consider again what happens. First of all, as before, asp.net creates an instance of the default class. This is our page class. So, it creates an instance of that class and that instance will contain child controls representing each of the runat server items we have on our web page and it performs default initialization based on the contents of mark up. Okay. So, that was all very well for the label. But obviously for the text box, that is only part of the story because the text box initially was empty and yet we know the user has just posted some data back to us and that likewise for the list box. The List box was empty but we have subsequently added items to it via the previous page load method on the first incarnation of the web page. So, there is clearly more initialization required over and above the basic initialization that we have in the static mark up.
So, let us go back to the code. Okay, so asp.net has created a page object and its controls. It has initialized the controls according to the static properties in the aspx file. Remember, these are the original values as per the first request. So, if you like the first stage of initialization. The second stage of initialization, because this is a post back, asp.net pc releases the view state and updates the controls. This returns the page to the state that was send before it resend to the client last time. So, for example, it will contain the Country List. The third stage of initialization is for asp.net to adjust the page even further according to the posted back form data. So for example, the text that the user has entered into the Name text box and items that we selected. All of these items of data that have been posted back have to be reflected in our controls.
So, by the time we get into the page load method, all of these three initializati
Transcription by:
Scribe4you Transcription Services