0

I have created a UserControl (Farm) in my SharePoint Project using VS2012 (for SharePoint 2010). I want to embed/host this in an application page.

I have added properties and events to the UserControl, but I cannot access these in code or in the ASPX (intellisense does not pick these up).

I get a warning "Element 'BlahBlahBlah' is not a known element. This can occur if there is a compilation error in the Web site, or the web.config file is missing.

I need to access properties and events from my user control, but I don't know what I am missing. I initially came across this post User Controls question but it did not shed much light on the matter.

I have the following code:

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace MySPProj.ControlTemplates.MyApp
{
    public partial class BlahBlahBlah : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public string ShowThisPropertyUpPlease
        {
            get { return "";  }
            set { }
        }
    }    
}

And drag the ascx from the ControlTemplates\MyApp which adds the code to the Application Page as follows:

<%@ Register Src="~/XXX/_ControlTemplates/MyApp/BlahBlahBlah.ascx" TagPrefix="uc1" TagName="BlahBlahBlah" %>

<uc1:BlahBlahBlah runat="server" id="BlahBlahBlah" />

I've tried Src="~/XXX/_ControlTemplates/..." and Src="~/_ControlTemplates/..." but it does not make a difference.

The code behind the application page does not recognise any of the properties. VS2012 just thinks that this is a normal UserControl.

I've omitted events for now.

Any thoughts?

Thanks

Andez

2 Answers 2

1
<%@ Register TagPrefix="uc1" TagName="BlahBlahBlah" src="~/_controltemplates/MyApp/BlahBlahBlah.ascx" %>

the above should work! unless you dont have that file in 14hive or wrongly named!

Also make sure that your folder in 14 hive is accessible! goto controltemplates folder find MyApp and right click and select "properties", click on security tab and then advanced button. Att the bottom you should see two checkboxes, the first one should be checked, you can also check the other (below "include inheritable permissions from this objects parent") and click ok! now you should inherit the permissions from the parent to the folder and subfolder/files so you can have access to that file ;)

when you click ok, it will uncheck the second checkbox which it should do but it will set the parent access to the children!

0

It was to do with the naming of the ControlTemplates folder. This is created as ControlTemplates. I came across an article on this issue (lost link now). Renaming the folder to _ControlTemplates resolved this issue.

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.