Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2008, 02:56 PM
Registered User
 
Join Date: Sep 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default When/How does hidden ViewState field get updated?

Regarding the hidden ViewState field... I'm looking for a verification of my understanding... When the User presses a Submit button, and then the form is sent back to the Server, is it true that just BEFORE this "sending back to the server" occurs, that the ViewState field is updated with the current values of the various form or html controls (unless a control's EnableViewState property is set to false)? And how does this updating occur? I assume that somewhere in the form (that is displaying in the client's browser) is some JavaScript to do this updating?
Thanks!
Rex
 
Old September 23rd, 2008, 03:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Rex,

Nope, that's not the case. The ViewState contains a representation of the page when it loaded in the browser and before you many any changes.

Let's assume you have a TextBox called TextBox1 with a Text property of "Imar". When the page first loads, this value is stored in ViewState and displayed in the control.

Then you change it to "Rex" and hit submit.

Both the hidden ViewState field and the TextBox's value are sent to the server. There, ASP.NET "unpacks" the ViewState field and applies it to the existing controls like the TextBox. It then loads data from the regular form fields over the existing data. That's how controls like a TextBox can react to events like TextChanged: they have access to the old and the new value.

So, the ViewState field is left untouched. All other data is sent using "traditional" web form technologies: as post fields.

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old September 23rd, 2008, 03:24 PM
Registered User
 
Join Date: Sep 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow, Imar. Great explanation - That was really clarifying. So my follow-up question is: If there is some JavaScript in the html that is sitting in the browser... that changes the value of a label due to some User input, then I assume that that new value of the label - since it is not an HTML form field - is NOT returned to the server (without some special code to store it in some other hidden field)? Is that right?
Rex
 
Old September 23rd, 2008, 03:30 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Exactly. While ASP.NET (and maybe AJAX) add interesting features to your web development toolbox, they don;t change how the web or how web browsers work. Traditionally, you would only send data using GET (through the QueryString) or using POST (with Form fields),

Normal "Labels" (which don't really exist at the client; they are merely simple <span> elements) don't submit themselves to the server. (And you should be glad that's the case, or you'd get as much inbound traffic as outbound traffic on your server).

So yes, depending on what you're doing: storing the data in a hidden field (ASP.NET has an <asp:HiddenField /> for example) is a good choice. But there are also many other ways to get data to the server.

Hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
 
Old September 23rd, 2008, 03:48 PM
Registered User
 
Join Date: Sep 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

excellent, Imar - I really appreciate the crystal clear explanations.
Thanks again,
Rex
 
Old September 23rd, 2008, 03:56 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
why does only my password field get updated??!!!! keyvanjan ASP.NET 2.0 Basics 5 May 28th, 2007 12:14 PM
pass value to the hidden field Dejitan ASP.NET 1.0 and 1.1 Basics 4 December 21st, 2006 03:13 AM
Hidden Field value error - PLEASE HELP jroxit Classic ASP Basics 5 September 18th, 2006 05:46 AM
Hidden field ashoka_klt ASP.NET 1.0 and 1.1 Basics 1 September 6th, 2006 07:12 AM
How to assign a value to a hidden field? Edward King Javascript How-To 1 May 3rd, 2004 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.