Welcome to weblogs.com.pk Sign in | Join | Help

Master Pages and FindControl

First let me confess; I am not good in UI programming. I am not in touch with it anymore. In my PSK2 project; I implemented ASPNET2’s Master Pages; and the problem I faced that if your page has any master page; the control’s ids get changed and FindControl(controlid) doesn’t work anymore. The following code doesn’t work

string controlToFind = "PanelRight";
Control parent = Page.FindControl(controlToFind);

You have to use something like

string controlToFind = "PanelRight";
Control parent = this.Master != null ? this.Master.FindControl("ContentPlaceHolder1").FindControl(controlToFind) : this.Page.FindControl(controlToFind);

Where ContentPlaceHolder1 is the asp:Contnet region where you are placing the page’s UI controls.

Published Thursday, December 15, 2005 5:31 PM by khurram
Filed under:

Comments

No Comments

New Comments to this post are disabled