Working on ASP.NET app, my project need to find control from page ,use bellow syntax to find control from a page:
public static Control FindControlRecursive(Control Root, string Id)
{
Control FoundCtl = new Control();
if (Root.ID == Id)
return Root;
foreach (Control Ctl in Root.Controls)
{
if (FoundCtl != null && FoundCtl.ID == Id)
{
Type ty = FoundCtl.GetType();
var r = FoundCtl as ty;
//var r = FoundCtl as Telerik.Web.UI.RadComboBox;
}
FoundCtl = FindControlRecursive(Ctl, Id);
//if (FoundCtl != null)
// return FoundCtl;
}
return FoundCtl;
}
For retrieve control value from the control need to cast. For cast use bellow syntax
FoundCtl as TextBox;
Is it possible to cast find control as bellow
Type ty = FoundCtl.GetType();
var r = FoundCtl as ty;