How to empty all textbox in a page

  • Thread starter HRsoft Informática
  • Start date
H

HRsoft Informática

I Have a page (clientes.aspx), inside a masterpage
I have some textbox, and when the user clicks the button 'Cancel', I need to
empty all controls. I tried this, with runtine error:

For Each txtControl As TextBox In Me.Controls
txtControl.Text = ""
Next

error message in runtime:
can't convert as object of type 'ASP.masterpage_master' in type
'System.Web.UI.WebControls.TextBox'.
 
B

bruce barker

pretty simple:


// find all textbox controls on page
Control[] list = ControlWalker(this, ctl => ctl is TextBox);

// clear text
foreach (Control ctl in list)
{
((TextBox) ctl).Text = "";
}

......


public delegate bool ControlWalkerMatcher (Control ctl);
public Control[] ControlWalker(Control ctl, ControlWalkerMatcher matcher)
{
ArrayList list = new ArrayList();
if (matcher(ctl)) list.Add(ctl);
for (int i=0; i < ctl.Controls.Count; ++i)
{
Control[] childList = ControlWalker(ctl.Controls,matcher);
if (childList.Length > 0) list.AddRange(childList);
}
return (Control[]) list.ToArray(typeof(Control));
}





-- bruce (sqlwork.com)
 
H

HRsoft Informática

Dear friend

Unfortunatelly, this syntax not compile:
Error 78 Type 'objcontrol' is not
defined. C:\inetpub\wwwroot\AjaxControlToolkitWebSite1\clientes.aspx.vb 317 28 C:\...\AjaxControlToolkitWebSite1\

--
Hércules
HRsoft Informática - Rio de Janeiro - Brasil
http://www.hrsoft.com.br



Mark Rae said:
"Patrice" <http://www.chez.com/scribe/> wrote in message

[top-posting corrected]
Plus you may have to recurse if you are on a container that holds
textboxes...

Yes, that's true - I should have mentioned that...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top