473,379 Members | 1,252 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 1910
In order for ASP.NET to be able to fire server-side events for "interactive"
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.nospam> wrote in message
news:OD**************@TK2MSFTNGP11.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
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. ...
1
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...
5
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...
4
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...
7
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...
2
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...
3
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...
2
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.