Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

This works!

(DropDownList)this.Page.Master.FindControl("myDropdown");
share|improve this answer

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" %>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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