How to empty all textbox in a page

  • Thread starter Thread starter HRsoft Informática
  • Start date 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'.
 
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)
 
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...
 
Back
Top