473,513 Members | 3,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Persistent ViewState

Hello everybody!

Imagine a form with several TextBox WebControls and two buttons "New" which
should clear the form and "Save". On reloading or leaving the page which
holds the form the TextBoxes should be cleared so I've disabled the
ViewStates of these TextBoxes by setting the EnableViewState property to
false.

The method which is bound to the OnClick event of the "New" button is
empty. When clicked a PostBack occurs which, theoretically, should be
sufficient to clear the TextBoxes because their state shouldn't be saved.
Unfortunately after the PostBack the data is still there! I've had a look
into the HTML source and found out that the value property of the TextBoxes
is set, so there's still a ViewState?! Even a ViewState.Clear() and/or
ClearChildViewState() within OnClick() doesn't work!

Disabling the ViewState for the whole page is no solution because the page
also contains a DataGrid and other controls which depend on the ViewState.

Please help!

--
Sincerely
Sven Jacobs
Nov 19 '05 #1
4 2205
ViewState is a different state persistance mechanism than the normal <form>
post data. ViewState is for data that is not part of the normal POST. The
text in a Label is saved in ViewState because a <span> doesn't post when
the form is submitted. The text in a TExtBox will be submitted, and thus
disabling viewstate has no effect on that.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hello everybody!

Imagine a form with several TextBox WebControls and two buttons "New"
which should clear the form and "Save". On reloading or leaving the
page which holds the form the TextBoxes should be cleared so I've
disabled the ViewStates of these TextBoxes by setting the
EnableViewState property to false.

The method which is bound to the OnClick event of the "New" button is
empty. When clicked a PostBack occurs which, theoretically, should be
sufficient to clear the TextBoxes because their state shouldn't be
saved. Unfortunately after the PostBack the data is still there! I've
had a look into the HTML source and found out that the value property
of the TextBoxes is set, so there's still a ViewState?! Even a
ViewState.Clear() and/or ClearChildViewState() within OnClick()
doesn't work!

Disabling the ViewState for the whole page is no solution because the
page also contains a DataGrid and other controls which depend on the
ViewState.

Please help!


Nov 19 '05 #2
> ViewState is a different state persistance mechanism than the normal <form>
post data. ViewState is for data that is not part of the normal POST. The
text in a Label is saved in ViewState because a <span> doesn't post when
the form is submitted. The text in a TExtBox will be submitted, and thus
disabling viewstate has no effect on that.


So what you saying is that the state persistance of a form is a feature of
HTTP / the browser? How to clear the form then, via JavaScript?

Thanks!

--
Sincerely
Sven Jacobs
Nov 19 '05 #3
> So what you saying is that the state persistance of a form is a feature of
HTTP / the browser? How to clear the form then, via JavaScript?


Forget that! After reading this article
http://aspalliance.com/articleViewer.aspx?aId=135 I think I now what the
difference between ViewState and PostBack data is.

So what I have to do is not to import the PostBack data on a special
condition (=New button clicked).

--
Sincerely
Sven Jacobs
Nov 19 '05 #4
No, the form persistance is a feature of the ASP.NET runtime, in that it
matches the control id in the POST data and fills the associated value from
that. See
http://msdn.microsoft.com/library/de.../viewstate.asp

To clear the form, loop through the controls on the form, and check if the
control is a textbox, or certain type of control, then set the value to an
empty string, or index to -1 if a droplist etc. It really depends on what
type of control you are working with as there is no generic way of clearing
a form (AFAIK).

--

- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)
"Sven Jacobs" <sv*********@web.de> wrote in message
news:17*****************************@40tude.net...
ViewState is a different state persistance mechanism than the normal <form> post data. ViewState is for data that is not part of the normal POST. The text in a Label is saved in ViewState because a <span> doesn't post when
the form is submitted. The text in a TExtBox will be submitted, and thus
disabling viewstate has no effect on that.


So what you saying is that the state persistance of a form is a feature of
HTTP / the browser? How to clear the form then, via JavaScript?

Thanks!

--
Sincerely
Sven Jacobs

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2778
by: Randell D. | last post by:
Folks, I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an existing unused connection. If my system was to go through a busy period whereby I seen an extra 50% or more activity for ten minutes or so, would the...
16
3288
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically I wish there was a way to have persistent in-memory objects in a Python app, maybe a multi-process one. So you could have a persistent dictionary...
0
2477
by: obhayes | last post by:
Hi All, Im using classic ASP (3.0) and I have a web farm with 2 webservers (webserver A and webserver B, both windows server 2003). I do not want to store any client specific information on the webserver (therefore do not intend to use the session object- as you cannot gaurantee which server the user will go to). I want to store a small value...
1
4594
by: brad | last post by:
Hi, Im using classic ASP (3.0) and I have a web farm with 2 webservers (webserver A and webserver B, both windows server 2003). I do not want to store any client specific information on the webserver (therefore do not intend to use the session object- as you cannot gaurantee which server the user will go to). I want to store a small value...
1
1569
by: Ryan | last post by:
The real reason for my previous post about intercepting Application_EndRequest (from outside of Global.asax) is because of a need to create a "non persistent page level cache". I can't seem to find an intrinsic property that exposes a Hashtable that gets reset for every page request. If someone knows of such a property, please let me know! ...
1
4341
by: Eric Lindsay | last post by:
I am trying to understand the differences between and uses of persistent, default and alternate styles. I have read http://www.w3.org/TR/REC-html40/present/styles.html section 14.3.2 on specifying external style sheets in link using combinations of rel and using or not using the title attribute. I think I sort of understand rel="alternate...
3
1255
by: Chu | last post by:
Hello All- I've got a Custom Web Control that with a public class that that sets a private variable inside the class. I plop the custom control onto my page and off I go. From my main page, I call the customPage.loadPage(10) and pass in a value of 10. The loadPage method sets var1 = 10 as expected; however, when the customPage's button is...
2
2745
by: Flinky Wisty Pomm | last post by:
Hi all, I've got a really annoying problem that I need to fix sharpish. I've got a GridView derived control which has a templated header and footer. It works wonderfully on the first render but then the header/footer vanish into thin air. If I add the header/footer onDataBound then they disappear when I do a postback with no databinding. If...
3
4284
by: sanchita | last post by:
Hello everyone, I didn't get any response in "Security" forum hence posting here again. I am having problem with persistent cookies. Even after setting "CreatePersistentCookie" to true in "FormsAuthentication.SetAuthCookie" I'm being logged out after the specifed timeout provided in "forms" element of web.config. I read somewhere that...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5703
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.