473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you clear textboxes on postback

When a page does a post back and there is data in a textbox, that
textbox will get automatically repopulated with that data due to the
posting of the form. Disabling viewstate has no affected on textbox
controls, so how do you make it so that the text box value is cleared
out on postback?
Nov 18 '05 #1
3 6182
<jw*****@gmail. com> wrote in message
news:d3******** *************** **@posting.goog le.com...
When a page does a post back and there is data in a textbox, that
textbox will get automatically repopulated with that data due to the
posting of the form.
That's correct - that's the whole point of having textboxes (and other
user-interactive) controls on web pages :-)
Disabling viewstate has no affected on textbox controls, so how do you
make it so
that the text box value is cleared out on postback?


Well, the trite answer would be to say that if a webpage contains a textbox
where the user can enter text, but the web app behind it isn't actually
interested in that text, why have it on the page in the first place?

But, clearing its value on postback is easy enough. In the Page_Load event
check whether Page.IsPostBck is true and, if it is, set the TextBox
control's Text property to "".
Nov 18 '05 #2
You can do this explicitly in the Load event:

if(IsPostBack)
{
TextBoxControl. Text = String.Empty;
}

--
Scott
http://www.OdeToCode.com/

On 4 Oct 2004 06:59:22 -0700, jw*****@gmail.c om wrote:
When a page does a post back and there is data in a textbox, that
textbox will get automatically repopulated with that data due to the
posting of the form. Disabling viewstate has no affected on textbox
controls, so how do you make it so that the text box value is cleared
out on postback?


Nov 18 '05 #3
Explicitly clear:

private void ClearTextboxes( )
{
textbox1.Text = String.Empty;
}

You can also loop through all of them and clear all. Explicit coding, even
when not necessary, makes the code clearer. In other words, I would clear
them explicitly, even if .NET did it for me. Reasoning: They may find that
they need to switch defaults some day (there is a 2.0 discussion on the
ADO.NET model right now).
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"jw*****@gmail. com" wrote:
When a page does a post back and there is data in a textbox, that
textbox will get automatically repopulated with that data due to the
posting of the form. Disabling viewstate has no affected on textbox
controls, so how do you make it so that the text box value is cleared
out on postback?

Nov 18 '05 #4

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

Similar topics

4
11420
by: T. Wintershoven | last post by:
Hello, I have a few textboxes placed on a SSTab control devided over 3 tabs Is there a way to clear all textboxes in one time in stead of one by one. Someone told me "Use for each item in.........." ??????????? T.i.a.
1
2017
by: Victor | last post by:
I'm retrieving values from the textboxes that I created dynamically. However I get commas appended to my text values and just a comma wherever the textbox is empty. Dont know what is causing this. Any suggestions please?
3
5000
by: Andreas Klemt | last post by:
Hello, how can I clear all ViewStates from a WebUserControl without doing a PostBack ? Thanks in advance, Andreas
1
1572
by: amrita | last post by:
hi i have a table in web form wth name table1.i need that wen i click on cancel button all the textboxes in that table becomes empty.ny ideas how to do it,doin in onclien side wud be greatly apppreciated thnx amrita
4
19754
by: Raterus | last post by:
Howdy, Simple question, but I can't figure out how to do it. I have a a page which is called initially with a querystring. After I get the querystring values, I don't need the querystring to appear in the url anymore. How can I get rid of it? A postback doesn't clear it, it just keeps tagging along. I tried Request.QueryString.Clear, but get "readonly" errors. I want to do this, because eventually I use server.transfer within this...
5
2594
by: \A_Michigan_User\ | last post by:
I'm using asp.net/vb.net/ado.net to create a very simple user interface. (Everything works if I use STATICALLY created textBoxes... but not when I make them DYNAMICALLY.) 1. Execute a SQL SELECT cmd to retrieve a record. 2. Loop through the dataReader values, creating textBox boxes dynamically, adding them to a Panel. (The database values are placed in these textboxes.)
2
2794
by: lanem | last post by:
I have an asp.net 2.0 page with a couple of textboxes and a gridview. On postback from a rowcommand from the gridview, the textboxes are clearing out. No other postbacks from the page are causing this. There is NO code whatsoever that deals with these boxes. One of them is just a dummy I set up for troubleshooting. I type something in it and cause a postback from another control and the value is still there as it should be. Then, when...
3
1566
by: jeroen.bolle | last post by:
I'm designing a form where the user can decide how many options for a poll he wants to add. There's a "+" button to dynamically add textboxes with javascript, without a postback. How do I access these newly generated <input type="text" id="..." /> elements with ASP.NET to save it to a database?
0
1515
by: rvdnieuwenhuizen | last post by:
Hi, The problem I cannot seem to solve: I have a page with a button control. In the On_Click eventhandler I dynamically add one TextBox each time the button is clicked. I add the textboxes to an update panel. I store the ID for the generated textboxes in the Viewstate, which I use in the Panels' INIT eventhandler to go ahead and instantiate the textboxes once again every postback. I use the, in my opinion, old mechanism of retreiving
0
9688
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
9546
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,...
1
10243
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
10030
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
9078
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.