1

I have built a custom SharePoint 2010 master page where I have dropped a standard asp.net DropDownList control. I also have wired up a code behind file where I want to manipulate that control from.

However for reasons not apparent to me, I am NOT able to reference this control in the code behind.

this.myDropdown

Intellisense does not show it. I cannot even get a handle on it using:

(DropDownList)Page.FindControl("myDropdown")

What am I doing wrong here?

Thanks

2 Answers 2

3

This works!

(DropDownList)this.Page.Master.FindControl("myDropdown");
1

You should be able to refer your control normally in codebehind class for the master. Check the steps to create a code behind for the master page :

1) Create a class inheriting from System.Web.UI.MasterPage.Declare the control in the class. For e.g.

 public class CustomMasterClass : System.Web.UI.MasterPage    
  {
        protected DropDownList myDropdown;

        protected void Page_Load(object sender, EventArgs e)
        {
            myDropdown.Width = 200;
        }
    }

2) Build it into a dll and add to GAC.

3) Add it to the safecontrols list on your web.config.

4) Add the same control to your master page as :

    <asp:DropDownList ID="myDropdown" runat="server"/>

5) Add reference to the class in your master. For e.g. :

<%@ Master language="C#" Inherits="CustomNamespace.CustomMasterClass, CustomNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ae015afe5f30fb68" %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.