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'm pretty new to SharePoint but am trying to get the hang of it. What I have been doing is creating ASP.NET web application pages and then deploying those to the SharePoint site. This works and is quick/easy to develop. However what I want to start doing is creating user controls in ASP.NET and wrapping those up in SharePoint web parts so that users can customize the pages themselves. I created the user control in ASP, and tested it in a web application page - it worked. However now I am trying to move it into the web part and it's not working.

What I did was create a new Visual Web Part project, then just copy and paste the markup and code behind (but not the namespace or register portions of those) to the default user control Visual Studio creates with the web part. I did not rename the default user control, or change its location, as I was hoping one of those things was causing the problem. But they were not. The problem I'm still getting is that it does not seem to find the user control. It gives me: "The file '/_CONTROLTEMPLATES/...' does not exist". But it does! What am I doing wrong? Maybe the user control is not being deployed to the right location (although that was checked, and it seems to be)? I am not sure what code you need to help answer this question, so just ask and I will be happy to supply it.

Thanks for reading,

Josh

share|improve this question
2  
Does your Visual WP deploy and add to a SharePoint page straight from new, before you start customising it? A good habit I always do is make sure the basic plumbing works, so initial web parts deploy and can be added, then I start adding stuff to them, so I know what breaks it when it breaks. –  James Love Mar 29 '13 at 14:01
    
Tried just making a webpart project and deploying it straight away, got the same error. Had not changed anything. –  Josh Apr 1 '13 at 12:01
add comment

3 Answers

What VS IDE are you using ? I know there are differences on the path

VS2010 "~/_ControlTemplates/[projectfolder]/[webpartname]/[usercontrolfilename]

VS2012 "~/_ControlTemplates/[projectfolder]/[usercontrolfilename]"

Bellow is an example for VS2012 that I am using

private const string _ascxPath = @"~/_CONTROLTEMPLATES/[ProjectFolder]/[usercontrolfilename]";
        protected override void CreateChildControls()
        {
            try
            {
                Control control = Page.LoadControl(_ascxPath);
                Controls.Add(control);
            }
            catch (Exception ex)
            {
                Controls.Clear();
                LiteralControl control = new LiteralControl(ex.ToString());
                Controls.Add(control);
            }
        }
share|improve this answer
add comment

So you want to make a visual webpart. You can goto this link... its on this site! look at my post it outlines how to make one and use the usercontrol within the visual webpart ;) with supporting links from msdn!

Can a user control be added to a Visual Web Part?

share|improve this answer
    
Already saw this before posting, didn't work. I even manually checked that the ascx was where it should be, which it was. Sharepoint just doesn't seem to see it. –  Josh Apr 1 '13 at 12:03
add comment

Sometimes i have the same issue. When you develop webpart you have to specify your usercontrol location in controltemplates. Somehow Visual Studio shows warning message that file is not exists. But when you deploy this web part it must works fine.

If you specify ascx file location from your dev folder this issue must dissapear. But after deploy your web part will not work.

Hope this help you.

share|improve this answer
add comment

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.