Click to See Complete Forum and Search --> : asp.NET change WebControl attributes


tookool4school7
05-17-2007, 03:45 PM
I want to add an onchange handler to all of a page's textboxes. I searched online and figured out the basic code to loop through all controls. (I have a recursive function that loops through all of Page.Controls and does a recursive call to handle any sub-controls).

Below is the code. The first time it is called, the parameter is null.


protected void setDataChangedHandlers(ControlCollection cc)
{
if (cc == null)
cc = Page.Controls;

foreach (Control ctrl in cc)
{


if (ctrl is TextBox)
{
ctrl.Attributes.Add("onchange", "onDataChanged");
}

if (ctrl.HasControls())
setDataChangedHandlers(ctrl.Controls);

}
}


I then realized that the Control class doesn't have an Attributes member, but WebControl does. Is there some way to access the WebControls on my page as actual WebControls?