473,503 Members | 4,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Most elegant way to clear all the text fields on asp.net page?

What is the most elegant way to clear all the text fields on asp.net
page? I just don't think that

txtShortName.Text = ""
txtYearFounded.Text = ""
txtCompanyCode.Text = ""
txtCity.Text = ""
txtOwnership.Text = ""
txtAssetsUnderManagement.Text = ""
txtNumberOfAnalysts.Text = ""
txtTotalStaff.Text = ""
txtCorporateOverview.Text = ""
txtInvestmentProcess.Text = ""
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtSuffix.Text = ""
txtPosition.Text = ""
txtNewSoftMinimum.Text = ""
txtNewHardMinimum.Text = ""

is a very smart way to do it.

Jul 23 '07 #1
2 2144
You could iterate through each control in a page using the Controls
collection and then see if the current control is the type of a textbox.

for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i].GetType() == typeof(TextBox))
((TextBox)this.Controls[i]).Text = string.Empty;

}

You may have to tweak this though to make sure you're getting the correct
child controls. For example, instead of using the page or controls full
control collection you may want to start with the htmlform control for the
page or create a recursive mechanism to ensure you're getting all the
controls in the page as this method will usually only load the top level
controls in the hierarchy.
--
Hope this helps,
Mark Fitzpatrick
Microsoft FrontPage MVP 199?-2006. 2007 and beyond

"Duk Lee" <du****@gmail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
What is the most elegant way to clear all the text fields on asp.net
page? I just don't think that

txtShortName.Text = ""
txtYearFounded.Text = ""
txtCompanyCode.Text = ""
txtCity.Text = ""
txtOwnership.Text = ""
txtAssetsUnderManagement.Text = ""
txtNumberOfAnalysts.Text = ""
txtTotalStaff.Text = ""
txtCorporateOverview.Text = ""
txtInvestmentProcess.Text = ""
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtSuffix.Text = ""
txtPosition.Text = ""
txtNewSoftMinimum.Text = ""
txtNewHardMinimum.Text = ""

is a very smart way to do it.

Jul 23 '07 #2
On Jul 23, 10:11 pm, Duk Lee <duk...@gmail.comwrote:
What is the most elegant way to clear all the text fields on asp.net
page? I just don't think that

txtShortName.Text = ""
txtYearFounded.Text = ""
txtCompanyCode.Text = ""
txtCity.Text = ""
txtOwnership.Text = ""
txtAssetsUnderManagement.Text = ""
txtNumberOfAnalysts.Text = ""
txtTotalStaff.Text = ""
txtCorporateOverview.Text = ""
txtInvestmentProcess.Text = ""
txtFirstName.Text = ""
txtMiddleName.Text = ""
txtLastName.Text = ""
txtSuffix.Text = ""
txtPosition.Text = ""
txtNewSoftMinimum.Text = ""
txtNewHardMinimum.Text = ""

is a very smart way to do it.
foreach (Control c in Page.Controls)
{
foreach (Control cc in c.Controls)
{
if (cc is TextBox)
{
((TextBox)cc).Text = String.Empty;
}
}
}

Jul 23 '07 #3

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

Similar topics

6
6058
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
16
12348
by: juglesh | last post by:
Hello, I need to look through the text on a page and replace certain words with an image or other word something like: read document find all instances of the word "blah" change all...
2
2359
by: Stephen Tang | last post by:
Hi, I'm relatively new at this language, so I've been trying to find parallels to problems I've run into in the past. This is the hypothetical problem: I want to write a CD inventory...
2
2101
by: tshad | last post by:
Is there a way to tell a screen on Postback to clear all the objects (or put them back to their defaults on Postback)? At the moment, I am just going through and setting them manually before...
2
2309
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling...
0
377
by: Ennio-Sr | last post by:
Hi all! After a very long struggle I finally succeded in transferring my old *.dbf file and the relating *.dbt (alias memo fields) to a pg table. For the time being I put the memo field in a...
3
1772
by: John Smith | last post by:
I have two text fields in a table. One is Height, one is width. Some examples of what might be each field: Height Width 35' 35' 8' 6' 4 to 6...
2
3748
by: letam | last post by:
Hello, Thank you in advance for any help, it will be most appreciated! I need to be able to disable several text fields, until the user enters a value in a certain text field. Once they enter a...
4
5030
by: Dan | last post by:
Hi all, I am creating a search table where the keywords field is made up of several text fields and this is causing me some problems. I can concatentate the text ok but i can't seem to concatenate...
0
7093
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...
1
7012
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...
0
7468
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...
0
5598
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,...
1
5023
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...
0
3180
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...
0
1522
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 ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
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...

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.