473,767 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.redire ct to the same page.

JK
Nov 18 '05 #1
5 14775
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.c om> a écrit dans le message de
news:eX******** ******@TK2MSFTN GP09.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.redire ct 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******** ******@TK2MSFTN GP11.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.c om> a écrit dans le message de
news:eX******** ******@TK2MSFTN GP09.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.redire ct 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.c om>
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.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: cpe00045a844590-cm014110201124. cpe.net.cable.r ogers.com 24.114.199.212Path: cpmsftngxa10.ph x.gbl!TK2MSFTNG XA06.phx.gbl!cp msftngxa06.phx. gbl!TK2MSFTNGP0 8
.phx.gbl!TK2MSF TNGP09.phx.gblXref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2374 25
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.redire ct 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.c om> wrote in message news:OE******** ********@TK2MSF TNGP11.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******** ******@TK2MSFTN GP11.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.c om> a écrit dans le message de
news:eX******** ******@TK2MSFTN GP09.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.redire ct 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****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

"JollyK" <Jo****@email.c om> wrote in message
news:OE******** ********@TK2MSF TNGP11.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******** ******@TK2MSFTN GP11.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.c om> a écrit dans le message de
news:eX******** ******@TK2MSFTN GP09.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.redire ct 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
4059
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 level (setting EnableViewState = false for every control), at the Page level with the @ Page...
1
4064
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:
4
3127
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 help!!!!!!!! Thanks!
2
1502
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 itself. - Page.EnableViewState = false; in page_load. How do I get the textboxes cleared after a postback without clearning them programmatically? J.
7
2109
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
1981
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 is not correcty raised (when i go from page 1 to 4 works, if i want to return to page 1, the event...
6
1935
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 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...
2
2915
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
2063
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
9571
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9405
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10013
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9960
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9841
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5280
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.