473,396 Members | 1,995 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,396 software developers and data experts.

Textbox retains value when EnableViewState = false

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 Response.redirect to the same page.

JK
Nov 18 '05 #1
5 14746
When you submit a form to a server, the browser always send the field values
(those who are named, not disabled and inside the form) to the server. This
is how a HTML form works "by design".

The "viewstate" is just an hidden field added by ASP.NET to store extra
informations and carry them over accross multiple server side executions of
the same page. It doesn't contains field values.

Patrice

"JollyK" <Jo****@email.com> a écrit dans le message de
news:eX**************@TK2MSFTNGP09.phx.gbl...
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 Response.redirect to the same page.

JK

Nov 18 '05 #2
Yes, the browser always sends the field values to the server. But after the
form is submitted, why does the asp.net textbox retain the text value. It
should be reset to the default value which is blank field. This issue only
with asp.net server controls. If i use <input type="text" name="txtname"
....... then I will not face this problem. I hope you are getting my
question.

"Patrice" <no****@nowhere.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
When you submit a form to a server, the browser always send the field values (those who are named, not disabled and inside the form) to the server. This is how a HTML form works "by design".

The "viewstate" is just an hidden field added by ASP.NET to store extra
informations and carry them over accross multiple server side executions of the same page. It doesn't contains field values.

Patrice

"JollyK" <Jo****@email.com> a écrit dans le message de
news:eX**************@TK2MSFTNGP09.phx.gbl...
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 Response.redirect to the same page.

JK


Nov 18 '05 #3
Hi JK,

That behavior is by design:

316813 PRB: Server controls persist their state when EnableViewState is set
to
http://support.microsoft.com/?id=316813

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online.microsoft.com

This post is provided "AS-IS" with no warranties and confers no rights.

--------------------
From: "JollyK" <Jo****@email.com>
Subject: Textbox retains value when EnableViewState = false
Date: Tue, 1 Jun 2004 09:48:10 -0400
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.1039
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1039
Message-ID: <eX**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: cpe00045a844590-cm014110201124.cpe.net.cable.rogers.com 24.114.199.212Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!cpmsftn gxa06.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP09.phx.gblXref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.framework.aspnet:237425
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

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 Response.redirect to the same page.

JK


Nov 18 '05 #4
With asp.net you can have "server side validators" , a feature
not present in "old" asp (or jsp, or php, or ..).
When a validator blocks a page, the user gets his/her page
back, complete with all (ok, nearly all: password is an exception)
values and the now-visible validator text.
If the input gets cleared after every postback, your user would need to
retype that input every time the validator blocks submission.

You, as the developer, can decide when the data is safe in the database
and only then clear the form. You could do this by clearing every named
input, or by writing a procedure that loops through all controls on the
page, clearing them in an appropriate manner.

Hans Kesting
"JollyK" <Jo****@email.com> wrote in message news:OE****************@TK2MSFTNGP11.phx.gbl...
Yes, the browser always sends the field values to the server. But after the
form is submitted, why does the asp.net textbox retain the text value. It
should be reset to the default value which is blank field. This issue only
with asp.net server controls. If i use <input type="text" name="txtname"
...... then I will not face this problem. I hope you are getting my
question.

"Patrice" <no****@nowhere.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
When you submit a form to a server, the browser always send the field

values
(those who are named, not disabled and inside the form) to the server.

This
is how a HTML form works "by design".

The "viewstate" is just an hidden field added by ASP.NET to store extra
informations and carry them over accross multiple server side executions

of
the same page. It doesn't contains field values.

Patrice

"JollyK" <Jo****@email.com> a écrit dans le message de
news:eX**************@TK2MSFTNGP09.phx.gbl...
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 Response.redirect to the same page.

JK



Nov 18 '05 #5
You have mixed up two concepts: ViewState and the value of a field posted
back. The key idea here is that properties directly connected to the form
value will always get the form value assigned on post back.

The TextBox.Text property is updated from Request.Forms on post back. It
reflects the live data. ViewState preserves the last known value of several
properties.
In fact, it preserves the value of the Text property although thats so it
can determine if the OnTextChanged event needs to fire. It needs a "before"
and "after" case to do that.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"JollyK" <Jo****@email.com> wrote in message
news:OE****************@TK2MSFTNGP11.phx.gbl...
Yes, the browser always sends the field values to the server. But after the form is submitted, why does the asp.net textbox retain the text value. It
should be reset to the default value which is blank field. This issue only
with asp.net server controls. If i use <input type="text" name="txtname"
...... then I will not face this problem. I hope you are getting my
question.

"Patrice" <no****@nowhere.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
When you submit a form to a server, the browser always send the field

values
(those who are named, not disabled and inside the form) to the server.

This
is how a HTML form works "by design".

The "viewstate" is just an hidden field added by ASP.NET to store extra
informations and carry them over accross multiple server side executions

of
the same page. It doesn't contains field values.

Patrice

"JollyK" <Jo****@email.com> a écrit dans le message de
news:eX**************@TK2MSFTNGP09.phx.gbl...
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 Response.redirect to the same page.
JK



Nov 18 '05 #6

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...
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...
2
by: John Dalberg | last post by:
I have a page with a few textboxes. When the page is posted, the textfields retain their values even though I have viewstate turned off. It's turned off in 2 different places. - The control...
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...
6
by: Chris | last post by:
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...
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...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...

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.