473,659 Members | 2,934 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.Te xt = ""
txtYearFounded. Text = ""
txtCompanyCode. Text = ""
txtCity.Text = ""
txtOwnership.Te xt = ""
txtAssetsUnderM anagement.Text = ""
txtNumberOfAnal ysts.Text = ""
txtTotalStaff.T ext = ""
txtCorporateOve rview.Text = ""
txtInvestmentPr ocess.Text = ""
txtFirstName.Te xt = ""
txtMiddleName.T ext = ""
txtLastName.Tex t = ""
txtSuffix.Text = ""
txtPosition.Tex t = ""
txtNewSoftMinim um.Text = ""
txtNewHardMinim um.Text = ""

is a very smart way to do it.

Jul 23 '07 #1
2 2151
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.C ount; 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.c omwrote in message
news:11******** **************@ o61g2000hsh.goo glegroups.com.. .
What is the most elegant way to clear all the text fields on asp.net
page? I just don't think that

txtShortName.Te xt = ""
txtYearFounded. Text = ""
txtCompanyCode. Text = ""
txtCity.Text = ""
txtOwnership.Te xt = ""
txtAssetsUnderM anagement.Text = ""
txtNumberOfAnal ysts.Text = ""
txtTotalStaff.T ext = ""
txtCorporateOve rview.Text = ""
txtInvestmentPr ocess.Text = ""
txtFirstName.Te xt = ""
txtMiddleName.T ext = ""
txtLastName.Tex t = ""
txtSuffix.Text = ""
txtPosition.Tex t = ""
txtNewSoftMinim um.Text = ""
txtNewHardMinim um.Text = ""

is a very smart way to do it.

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

txtShortName.Te xt = ""
txtYearFounded. Text = ""
txtCompanyCode. Text = ""
txtCity.Text = ""
txtOwnership.Te xt = ""
txtAssetsUnderM anagement.Text = ""
txtNumberOfAnal ysts.Text = ""
txtTotalStaff.T ext = ""
txtCorporateOve rview.Text = ""
txtInvestmentPr ocess.Text = ""
txtFirstName.Te xt = ""
txtMiddleName.T ext = ""
txtLastName.Tex t = ""
txtSuffix.Text = ""
txtPosition.Tex t = ""
txtNewSoftMinim um.Text = ""
txtNewHardMinim um.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).T ext = String.Empty;
}
}
}

Jul 23 '07 #3

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

Similar topics

6
6081
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 parse the filename. <form name='form1' method='POST' enctype='multipart/form-data' action='sub.asp'> <input type='text' name='title1' value='value1'> <input type='file' name='file1'>
16
12361
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 instances of the word "blah" to <img src="MyPicture.jpg" >
2
2367
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 application. There is a page where it asks the user for the number of tracks on a CD. After they enter the number of tracks, I would like to generate that number of text fields on the page (i.e. if user enters 30, I want to generate 30 text fields), so...
2
2107
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 reading new records. Thanks, Tom
2
2321
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 functions very easy and nice. Anyway, I'm afraid that I haven't understood the data binding things correct. I'm using MySQL Connector/.NET to access my database from the
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 separate table having two fields only (i.e.: n_memo integer, memo text) which can be related to the main table in a view.
3
1780
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 feet Indefinite 3' 3' 33" 18" - 24" 28" 18" - 24"
2
3763
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 number, the text field items would be enabled. It's an order form, where they can pick and choose from several items to make up a case, they must enter how many cases first before being able to choose form the list of items. The list of items are...
4
5036
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 matching records here is the cursor loop. I'm not a fan of cursors but also didn't see another way of achieving this. declare @ptr1 varbinary(16) declare @Ptr2 varbinary(16) declare @profileid int declare @x int
0
8427
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
8746
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...
0
8627
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
7356
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...
1
6179
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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
1975
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.