The easiest way to find a control is to do a recursive search, as your current method probably doesn't work because the controls are nested.
public static Control FindControlRecursive(Control root, string id)
{
if (id == string.Empty)
return null;
if (root.ID == id)
return root;
foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}
return null;
}
You can use this method as follows:
HtmlGenericControl div = (HtmlGenericControl) FindControlRecursive(pnl, "divMessage");
source
share