Monday, December 28, 2009

.Net FindControl - find your html controls

Sometimes the FindControl method won't find your control, if its on the masterpage or if its inside a contentplace holder.

To fix this:

ContentPlaceHolder cph = this.Form.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
HtmlControl myFrame = (HtmlControl)cph.FindControl("iframe01");
myFrame.Attributes["src"] = url_geo;


HtmlControl myFrame = (HtmlControl)this.Master.FindControl("controlid");


P.S.: Your iframe may need the runat="server" tag for this to work!

No comments:

Post a Comment