473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enableviewstate =false question

I've created two textboxes and one button on my web form. I then set the
EnableViewState property of Textbox1 to False. Textbox2 is set to True.
The button has no code in it - It simply has an auto post back which reloads
the page.

I run the web application and type "test 1" into Textbox1 and "test 2" into
Textbox2. I click the button and the page reloads. Textbox1 has the value
of "test 1". Textbox2 has the value of "test 2".

Am I missing the point here - Shouldn't the value of Textbox1 now be blank
again because I set its EnableViewState to False?
Thanks in advance.
Nov 18 '05 #1
6 1927
In order for ASP.NET to be able to fire server-side events for "interactiv e"
controls (such as a TextBox) it has to be able to detect when the values
have changed. For this it requires the original value (when the page was
sent to the client) to be available on a postback, and so it has to store
this in the page (using the viewstate). Even when you turn off viewstate,
some value are still maintained for some controls. Turning off viewstate is
used to minimize the data round-tripped to the client (try it with a
DataGrid to see the effects). If you want to "blank" a Textbox you should
change the Text property during your handling of the postback.

"Chris" <cw@community.n ospam> wrote in message
news:OD******** ******@TK2MSFTN GP11.phx.gbl...
I've created two textboxes and one button on my web form. I then set the
EnableViewState property of Textbox1 to False. Textbox2 is set to True.
The button has no code in it - It simply has an auto post back which reloads the page.

I run the web application and type "test 1" into Textbox1 and "test 2" into Textbox2. I click the button and the page reloads. Textbox1 has the value of "test 1". Textbox2 has the value of "test 2".

Am I missing the point here - Shouldn't the value of Textbox1 now be blank
again because I set its EnableViewState to False?
Thanks in advance.

Nov 18 '05 #2
Thanks a lot for Alex's informative suggestions.

Hi Chris,

As Alex has mentioned, some certain webserver controls can still post their
values when we disable its viewstate. As for the TextBox control, it is
actual rendered as an <input type=text ...> html element when the page
render back to the client browser. And the TextBox's "Text" propery is
really be stored in the ViewState. However, when the page is post back ,
the TextBox's new value will be also post back because it is represent by
the "value" attribute of the <input type=text ..> element which is
accessable from the Request.Form[] collection. For example, if we have the
following TextBox in page
<asp:TextBox id="txt" runat=server Text="Initial value"></asp:TextBox>

when render to client, it is like below:

<input type="text" id="txt" name="txt" value="intial value" />

Then ,when the client user input new value in it, the "value" attribute's
value will change to the new input and when the page is post back, the new
value will be post together and we can use
Request.Form["txt"] to get it.

That's why we can get the textbox's value though the ViewState is disabled.
Then, what does the "Text" property (in the ViewState) do? Well, that's
anothe thing, let's have a look at the TextBox's serverside lifecycle:

When a page with a TextBox control is post back, (suppose the TextBox's ID
is "txt"), then,

In the page's LoadPostData event, it will get the TextBox's new input value
from the Request.Form[] collection as I mentioned above. Also, the page
will retrieve the TextBox's old value from the ViewState and compare them,
if different , it assgin the new Value to the "Text" property of the
TextBox and later the TextBox's TExtChanged event will be fired.. So if we
disable the ViewState , everytime the page will find that the new input it
different from the old value( because the old value in viewstate doesn't
exist ) and the TextChanged event will be fired.

In addition ,here is a good tech article which demonstrate the details of
the asp.net 's VIEWSTATE :

#Understanding ASP.NET View State
http://msdn.microsoft.com/library/de...us/dnaspp/html
/viewstate.asp

Also, if you have interests , you can try using the .NET Reflector tool to
have a look at the TextBox's source code , that'll explain the question
more clearly :).

Hope all these helps. If you still have anything unclear, please feel free
to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Nov 18 '05 #3
Hi Alex,

Many thanks for the explanation. Do you know of any lists/websites that
show which values are retained in viewstate, or do you have to work it out
for yourself.

Thanks,
Chris

Nov 18 '05 #4
Hi Chris,

Have you also had a chance to see the suggestions in my former reply? As
for all the buildin web controls in asp.net , there hasn't such a list
which shows all the VIEWSTATE persisted properties. But generally, we could
see if I control's properties is not able to be stored in the control's
rendered html and also need to be used in the sequential post back, that
should be persistent in VIEWSTATE. Also, as I mentioned in the former
thread, using the .NET Reflector tool to have a clear look at the
webcontrol's code is sometimes much more helpful:)

If you have anything else unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
Hi Steven

Many thanks for your help. This explains it well - I am sorry I missed your
post yesterday - must have got distracted and thought I read it all.

I will check out the reflector tool.

Thanks,
Chris
Nov 18 '05 #6
Thanks for the followup Chris.

I'm glad that the suggestions are of assistance. Also, if you have any
other questions later, please feel free to post there.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7

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

Similar topics

0
4044
by: Dave Verwer | last post by:
Hi I have a problem which is easily reproducable using VS.NET 2003 and the .Net framework 1.1 (not tested with framework 1.0) regarding disabling ViewState for dynamically created controls. Basically setting EnableViewState=false on controls created dynamically does not stop the viewstate being stored! I have tried this at the control...
1
4052
by: Ravikanth[MVP] | last post by:
Hi Even though the Viewstate has been disabled, ASP.NET still uses about twenty bytes for Viewstate. Not only can you disable Viewstate at the page level, but you can also disable Viewstate at the control level. For example, the following code disables Viewstate for a ListBox control:
5
14753
by: JollyK | last post by:
Hello all, I have always been having this issue and wondering what the solution is. When I set the enableviewstate property to false for a textbox, the textbox always retains its value after a postback occurs. Why is this? I want the textbox to become empty after postback. How can I do it without setting textbox.text = "" and without doing...
4
3110
by: Bruce Chao | last post by:
I tried to turn off viewstate and so I added enableViewState=false in side the Page directive, rebuild the page, test it. - not working Then I set all controls on the page so all their enableViewState is also false -- still, not working. After doing al these, I still see the hidden viewstate variable in the HTML source. Please...
7
2092
by: Brian Henry | last post by:
Hi, I want EnableViewState = false turned on to optimize the end output page (it was over 600KB with it on) but when i turn it off, our pageing functionality no longer works mainly the PageIndexChanged event no longer fires, how do you handle this with enable view state as false? thanks!
2
1974
by: michele | last post by:
Hi, i'm using a datagrid control in my webform, with AutoGenerateColumns=false; it work very well if EnableViewState=true; including paging and sorting, but this cause a big performance issue, so i've decided to set EnableViewState=false: now the events related to the datagrid have some strange behavours: for example the PageIndexChangedEvent...
3
1560
by: Mortar | last post by:
i would like my datagrids to be both sortable and pageable. All the examples i have found so far use methods which require the datagrid's enableViewState method set to true. This can be bad if the datagrid is holding lots and lots of data. is it possible to change the link on the datagrid header column links somehow? I would basically like...
2
2907
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
1
2055
by: =?Utf-8?B?VmlkZHM=?= | last post by:
Hi All, I am not able to get the sort event when i EnableViewState =false for data grid. Is there any relation betwn those two.Please comment. How can I get through this problem? Thanks in advance. Regards,
0
7432
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
7689
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7943
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...
1
7456
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6022
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...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3490
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
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
743
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.