Wrox Programmer Forums
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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 8th, 2010, 08:56 AM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default Viewstate engine problem

Hello,

If i remember right.. the fact that the fields keep their value once submitted is the result of the viewstate engine.

The problem is that in some scenario you have to disable it (such when you need to get the data back from server as an exemple) so when i try to disable it.. the data still are keep to the form and fields.. is there a way to disable it to clear out each fields.. once submitted ?

Thanks.
 
Old September 9th, 2010, 03:33 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:
If i remember right.. the fact that the fields keep their value once submitted is the result of the viewstate engine.
Close, but not cigar ;-)

The state engine (without ViewState) does this for you. When you submit a form control (such as a text box) ASP.NET is able to prepopulate the control again based on the value in the submitted form. This works for controls that submit their data through a form, such as text boxes, select lists, radio buttons and so on.

For controls that cannot do this themselves (a Label, a GridView, etc) or custom code, View State is used which uses the hidden __VIEWSTATE field to send the data from and to the server.

So, even if you disable View State, a TextBox control still retains its value after a postback. To clear its value, simply set it to an empty string:

myTextBox.Text = String.Empty.

Hope this helps,

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!
The Following User Says Thank You to Imar For This Useful Post:
Rushino (September 9th, 2010)
 
Old September 9th, 2010, 07:43 AM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default

Oh i see lol i understand now.

Thanks a lots that more clear to me now.
 
Old September 12th, 2010, 01:48 AM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks

This really helped me too, I was struggling with the same issue for few days.

Thanks a ton!!!





Similar Threads
Thread Thread Starter Forum Replies Last Post
survey engine hosting problem vasancer BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 20 May 27th, 2009 04:07 PM
problem with viewstate and postback hertendreef ASP.NET 2.0 Professional 1 May 31st, 2008 04:05 PM
Problem with DropDownList's Viewstate. vinod ASP.NET 2.0 Basics 1 January 19th, 2008 08:07 AM
problem with viewstate? dll? namespace? [email protected] ASP.NET 1.0 and 1.1 Basics 0 June 19th, 2003 02:52 PM





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