Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2007, 02:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. After reading this thread several time, I still think that your original code is better than this.. the original way only change several textbox, instead the new idea loop around all the controls in the page looking for textboxes (what if you have other textboxes that you don't want to change??)...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old August 7th, 2007, 06:59 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Normally when I use this code, I place the code inside of a container control such as a panel so

foreach(Control ctrl in panel1.Controls)
{
//code
}

However, the reason you are having your above problem is because the Form, in and of itself, is a container control so you need to do something like this:

foreach(Control ctrl in Page.Controls)
{
 if(!ctrl is TextBox)
 {
   if(ctrl.HasControls)
   {
     ReplaceText(ctrl);
   }
 }
 else
 {
   TextBox t = (TextBox)ctrl;
   t.Text = t.Text.Replace("\"", "");
 }
}

private void ReplaceText(Control crl)
{
foreach(Control ctrl in crl.Controls)
{
 if(!ctrl is TextBox)
 {
   if(ctrl.HasControls)
   {
     ReplaceText(ctrl);
   }
 }
 else
 {
   TextBox t = (TextBox)ctrl;
   t.Text = t.Text.Replace("\"", "");
 }
}

So, with all of that said, you are now at a point where it is more effecient to just deal with the 10 lines of code that you originally used to replace your quotes.

To address Gonzalo's point, he is right, this is going to change every value of every textbox on a given page however, given your original post, you did not say that there were textboxs on the page that this behavior should not be persisted to.

In all reality the only time I would ever use a recursive call such as above is if I am working with a page that has many dynamic controls (and control containers for that matter) and the id's of said controls are unknown to me at runtime.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
 
Old August 8th, 2007, 11:36 AM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK fair point.

Thanks for all your efforts and contributions.

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Efficiency Kev_Akas PHP Databases 1 May 13th, 2008 09:24 AM
code efficiency sxstat90 SQL Language 1 March 8th, 2005 04:42 PM
efficiency qn - writing and saving xml file ak Classic ASP XML 1 March 2nd, 2004 05:26 PM
Function Efficiency Ben Access VBA 3 November 20th, 2003 04:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.