Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Most elegant way to clear all the text fields on asp.net page?

Reply
Thread Tools

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

 
 
Duk Lee
Guest
Posts: n/a
 
      07-23-2007
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.

 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      07-23-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.
>



 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      07-23-2007
On Jul 23, 10:11 pm, Duk Lee <(E-Mail Removed)> wrote:
> 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;
}
}
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the most elegant way of doing this? Alex Buell C Programming 3 02-04-2009 10:07 AM
Most elegant way to 'reroute' Text widget events? Kenneth McDonald Ruby 2 09-02-2008 03:48 AM
most elegant way to split text file randomly into n parts? Markus Dehmann Perl Misc 6 12-14-2007 09:07 PM
Most elegant way to generate 3-char sequence Rob Cowie Python 28 06-13-2006 01:40 AM
Elegant way to clear a struct ? Nils Emil P. Larsen C Programming 11 07-07-2003 12:37 AM



Advertisments