clickclickbang
asked on
Cast Control To WebControl
I am iterating through controls on a page and need to cast them to a webcontrol to access attribute property.
Can someone give me a quick example of how to cast a control to a web control?
public void FetchControls(Control c)
{
try
{
WebControl wc = (WebControl)c;
DistributeToSets(wc);
// Run FetchControls again if the current control is a parent and has child controls.
if (c.HasControls())
{
foreach (Control cc in c.Controls)
{
FetchControls(cc);
}
}
}
catch (Exception ex)
{
debug("Failed casting from Control to WebControl.");
debug(ex.Message);
}
}
Executing this gives me an invalid cast exception for ALL the controls.
Any tips will be appreciated!
Can someone give me a quick example of how to cast a control to a web control?
public void FetchControls(Control c)
{
try
{
WebControl wc = (WebControl)c;
DistributeToSets(wc);
// Run FetchControls again if the current control is a parent and has child controls.
if (c.HasControls())
{
foreach (Control cc in c.Controls)
{
FetchControls(cc);
}
}
}
catch (Exception ex)
{
debug("Failed casting from Control to WebControl.");
debug(ex.Message);
}
}
Executing this gives me an invalid cast exception for ALL the controls.
Any tips will be appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks much guys!
Button1.Style.Add("Height"
TextBox1.Style.Add ("Color","Green");
The syntax is
controlname.Style.Add(Attr