I have created a custom page layout with a div tag in it. I am trying find this div from a visual webpart code behind,but the control is always null.
Page Layout
<div id="abc" runat="server">....</div>
Visual WebPart code
Control ct = findDivControl(Page,"ctl00_PlaceHolderMain_abc");
Recursive method
protected HtmlGenericControl findDivControl(Control c, string id)
{
HtmlGenericControl foundControl = (HtmlGenericControl) c.FindControl(id);
if (foundControl != null)
return foundControl;
foreach (Control ctx in c.Controls)
{
foundControl = (HtmlGenericControl) findDivControl(ctx, id);
if (foundControl != null)
return foundControl;
}
return null;
}