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 created visual web part and copied custom web control which I'd like to use. My control looks as below:

namespace AppsListWebPart
{
    [ToolboxData("<{0}:CustomImageButton runat=\"server\"></{0}:CustomImageButton>")]
    public class CustomImageButton : LinkButton
    {

        public string ImageUrl { get; set; }

        /// <summary>
        /// This image will override any background mentioned in CSS. Use this in case you want to use ASP.net (non-CSS) style URLs (like ~/images/add.png)
        /// </summary>
        public string BackgroundImageUrl { get; set; }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {

            if (!string.IsNullOrEmpty(this.BackgroundImageUrl))
            {
                base.Style.Add("background", "url('" + base.ResolveUrl(this.BackgroundImageUrl) + "‘) left center no-repeat");
            }
            base.Style.Add("text-decoration", "none");
            base.Style.Add("text-align", "center");
            base.RenderBeginTag(writer);

        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write("<span style='vertical-align:top;'>");
            base.RenderContents(writer);
            writer.Write("</span>");
            writer.Write("<img border='0′ style='margin-top:2px;margin-left:3px' src='" + base.ResolveUrl(this.ImageUrl) + "‘ />");
        }

    }

}

In my webpart's ascx file, I try to register this web control by:

<%@ Register TagPrefix="spt" Namespace="AppsListWebPart" %>

Unfortunately, IntelliSense doesn't show any spt: tags and when I try to run my web part with this code written by myself:

<spt:CustomImageButton runat="server"></spt:CustomImageButton>

I get the error: Unknown server tag 'spt:CustomImageButton'.

How to perform correct custom web control registration?

Edit

I changed the registration line to:

<%@ Register TagPrefix="spt" Namespace="AppsListWebPart.AppsListVisualWebPart" Assembly="AppsListWebPart" %>

and changed my web control namespace to AppsListWebPart.AppsListVisualWebPart

and I'm getting now:

Could not load file or assembly 'AppsListWebPart' or one of its dependencies. The system cannot find the file specified. 

In editor thou, when I enter spt: I see now my AppsListVisualWebPartUserControl, but not CustomImageButton.

In webconfig I found AppsListWebPart assembly registered in safecontrols, but nothing more.

share|improve this question
    
Is your AppsListWebPart.dll getting deployed correctly to the GAC? I'm assuming you are using VS 2010 to deploy? –  Kit Menke Oct 10 '11 at 16:57

5 Answers 5

up vote 2 down vote accepted
+25

(Edit) Sorry, I have deleted my previous answer because I didn't noticed that you said that you have changed your control namespace to be the same used in the Register tag.

You said that the exact error is "Could not load file or assembly 'AppsListWebPart'"... could you try to change the AppsListWebPart string in your register comand to the assembly full name?

To be clearer:

<%@ Register TagPrefix="spt" Namespace="AppsListWebPart.AppsListVisualWebPart" Assembly="AppsListWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aaaaaaaaaaaaaaaa" %> 

(change the token and version to reflect your deployment situation)

share|improve this answer
    
how can I determine assmebly's full name? –  jjczopek Oct 10 '11 at 13:46
1  
Well, you can use the Strong Name Tool (SN.exe, see the page msdn.microsoft.com/en-us/library/k5b5tt23(v=vs.80).aspx for more detail ) to recover your assembly public key token and just build the rest from your project settings. Alternatively you can use the AssemblyName.FullName property to get the full name in codebehind (this blog post provides more info). You can also find out your assembly public key token by looking at the GAC (if your dll is GAC-deployed) –  SPArchaeologist Oct 10 '11 at 14:05
1  
BTW, you could also consider implementing a simple Visual Studio external tool that would return the full name of a given assembly. This page provides full guidance for the task. –  SPArchaeologist Oct 10 '11 at 15:08
1  
Get the full Assembly name using tool ILSpy @ wiki.sharpdevelop.net/ILSpy.ashx , browse to the assembly using the tool and find the full assembly name then replace from : Assembly="AppsListWebPart" to: Assembly="AppsListWebPart, Version=1.0.0.0, , Culture=neutral, PublicKeyToken=xxxxxxx" –  Vamsi Oct 10 '11 at 19:52

The correct format to register a tagprefix is:

 <%@ Register Tagprefix="[tagName]" Namespace="[Namespace]" Assembly="[AssemblyName], Version=[Version], Culture=[Culture], PublicKeyToken=[PublicKeyToken]" %>

Below is the example:

  <%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

Please make sure your assembly is in GAC and try IISRESET or Application Pool Recycle. For security reasons, if you choose BIN deployment instead of GAC, Please ensure assembly is in the web application's /bin folder.

share|improve this answer

I had the same problem as you. I created a custom web server control based on SPGridView and tries to add it to my Visual Web Control. I solved the problem with this 2 steps.

<%@ Register TagPrefix="cc1" Assembly="CustomSpGridView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=562a273772bbe3d8"
Namespace=CustomControl" %>
  1. Add this to the page that I want to use the custom control.

  2. Double click on the Package folder, this will open up the package designer. Click on the advance button at the bottom. Refer to the screen shot below

enter image description here

Try this, cause this solved my problem.

Hope this helps.

share|improve this answer

I assume you are packaging this web part as a solution. If so, check the manifest file in your solution package. You can do this in visual studio 2010 by clicking opening up the package editor and clicking on the Manifest tab. If you don't see the new namespace there registered as a safe control, that is at least part of the problem. Make sure the solution package name is correctly named and that it appears in the manifest file.

share|improve this answer

jjczopek, It seems it hasn't been registered properly. To be sure just check your webconfig and see if anything has been registered there. How are you deploying it is it through visual studio? Patrick

share|improve this answer
    
I found only my AppsListWebPart assembly registered in safe controls but nowhere else in web.config. –  jjczopek Oct 7 '11 at 10:02

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.