Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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 July 13th, 2010, 12:36 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default Why does so much code get generated

After spending allot of years in the Classic ASP world. I am a little over half way through a beginnning ASP.NET book using VS 2010.

Over the years I have always tried to write clean neat code. Within reason trying to write as few lines as possible to get my outcome. Nice short meaningful ID/Name/Value strings etc...

I can not beleive the state of the code Visual Studio creates after viewing the source in the browser. Even a fairly simple page. I mean what on earth is this neccesary for:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTk4NTYxMTcyMw9kFgJmD2QWAgIDD2QWCAIFDzwrAA0 BAA8WAh4HVmlzaWJsZWhkZAIJDzwrAAkCAA8WCB4NTmV2ZXJFe HBhbmRlZGQeC18hRGF0YUJvdW5kZx4MU2VsZWN0ZWROb2RlZB4 JTGFzdEluZGV4AghkCBQrAAUFDzA6MCwwOjEsMDoyLDA6MxQrA AIWDh4EVGV4dAUESG9tZR4FVmFsdWUFBEhvbWUeC05hdmlnYXR lVXJsBQ0vRGVmYXVsdC5hc3B4HgdUb29sVGlwBRJHbyB0byB0a GUgaG9tZXBhZ2UeCERhdGFQYXRoBQ0vZGVmYXVsdC5hc3B4Hgl EYXRhQm91bmRnHghFeHBhbmRlZGdkFCsAAhYSHwYFB1Jldmlld 3MfCmcfBQUHUmV2aWV3cx8HBRUvUmV2aWV3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BRNodHRwOi8vcDJwLndyb 3guY29tZAICDw8WAh8AaGRkGAEFHl9fQ29udHJvbHNSZXF1aXJ lUG9zdEJhY2tLZXlfXxYBBQ9jdGwwMCRUcmVlVmlldzEEOr7fK NOD7mtal8YtuOjZpKmVnyaZXJcQP4aMmint6A==" />

OMG Im in dis belief! Is this just how it is in the .net world? I know classic ASP is dying a slow death and this .net world is where things have, and are going. Gee what a mess to walk into....
__________________
Wind is your friend
Matt
 
Old July 14th, 2010, 03:00 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

ASP.NET uses __VIEWSTATE in place of using Session variables, to keep track of what is going on in the server vs. what is going on in the browser. Basically, __VIEWSTATE is an encrypted form of the info that ASP.NET needs to reconstruct the server code to the same state each time.

For example, you may have noticed that ASP.NET is aware of *BOTH* the text and value of the <option>s of a <select>. Yes HTML will always send back *only* the value= of an <option>. So ASP.NET "connects" those value= values to the text using this __VIEWSTATE info. Similar stuff abounds. It's really all the same that you *could* do in classic ASP using session variables (or your own hidden fields or tricks with value=) but it's all done for you. Really, it's very little overhead in the browser (much smaller than, say, even the smallest <img> you might display!) for a lot of gain in functionality.
 
Old July 15th, 2010, 06:26 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Form my very limited .net experience (page 432 of Imar's Beginning .net 3.5) I figured this was where that crazy hiden form field came from. I guess my little rant was out of suprize coming from someone who is used to only seeing code that is intentionaly put there. Thank you for your time
__________________
Wind is your friend
Matt
 
Old July 16th, 2010, 06:32 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

It's really just a trade-off. MS could have chosen to put that same info into Session variables (or equivalent) and stored it all on the server. For most low-volume sites, that's probably a preferable answer. But for really high-volume sites, keeping stuff *off* the server is a good idea.

I'm not really defending their choice, per se. Just explaining it. I know I have occasions when using classic ASP when I've needed to "persist" a *LOT* of information, and I've used session variables because the sites were relatively low volume. But I've always been aware that session variables can indeed be "poison" to a high volume site.
 
Old July 18th, 2010, 08:31 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
Yes HTML will always send back *only* the value= of an <option>. So ASP.NET "connects" those value= values to the text using this __VIEWSTATE info.
I don't think that's accurate, is it? Doesn't it know the value and the text because it recreates the control tree at the server and gets a selected value from the client?

ASP.NET does use ViewState for similar stuff though, like the text in a TextBox before it gets sent to the browser. That way, when users enter a different text, the TextChanged event can be fired. ViewState is also used heavily by the data controls to store data, primary keys and so on.

In the book you'll find a number of tips on minimizing the impact of ViewState by turning it off where possible. ASP.NET 4 has greatly changed the ability to fine-tune this (and thus minimize it even further) with the introduction of the ViewStateMode attribute: http://www.mostlylucid.net/archive/2009/01/28/1312.aspx

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
never have to customize the auto-generated code markandeya BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 1 June 23rd, 2010 03:09 AM
windows code generated siji44 Visual Studio 2005 1 September 11th, 2007 12:32 PM
Generated Code Overwriting PWD rodmcleay ADO.NET 1 November 28th, 2005 04:27 AM
screen generated very slow l1234567890 JSP Basics 1 March 16th, 2005 11:06 AM
Generated dataset and autoincrement dbradley ADO.NET 5 February 2nd, 2005 01:14 AM





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