In my mobile application i wanted to find a control that was in a devicespecific tag. I am surprised there was no dirac way to find that control and following work-around solved my issue.
public Control GetControl(string ID, Control cstart)
{
Control co = new Control();
Type t = typeof(System.Web.UI.MobileControls.TemplateContainer);
if (cstart.HasControls())
{
foreach (Control c in cstart.Controls)
{
if (co != null)
{
if (t.IsInstanceOfType(c))
{
co = c.FindControl(ID);
}
else
{
if (c.HasControls())
{
co = GetControl(ID, c);
}
}
}
}
}
return co;
}
If you want to find a dropdownlist named "ddlItems" inside devicespecific tag use
DropDownList ddl= (DropDownList)GetControl("ddlItems",this );
I am still searching for a simpler way to do this. In the time hope this will help in some way.
cheers
Happy coding,
samitha
No comments:
Post a Comment