1
votes

There is probably a very simple solution to this problem but since I do not know Sharepoint at all and cannot seem to google my way to wisdom on this one maybe one of you guys can steer me in the right direction.

Background: Currently I am working in a project where a part of our web solution is constituted by Sharepoint and I have absolutely no previous experience from Sharepoint. Lately I have been struggling with what looks like a very simple task, adding a (web) user control to one of the Sharepoint pages in our solution. There are two important requirements on this task;

  • The user control and the code-behind must lie in and make up a separate assembly
  • That assembly must be signed

The user control assembly is really another ASP.NET Web application with a Default.aspx so I may debug the user control with mockups using Cassini. When I debug it through Default.aspx it works fine, the user control is displayed and I can use it as intended.

I have these lines in my web.config:

<SafeControls>
[..]
<SafeControl Assembly="MyMainNamespace.SubNamespace.SelectorPopup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7fa78676161515a2" Namespace="MyMainNamespace.SubNamespace.SelectorPopup" TypeName=" *" Safe=" True " />
[..]
</SafeControl>

And on the Sharepoint page I have put the following:

<% @Register TagPrefix= "Selector" Namespace="MyMainNamespace.SubNamespace.SelectorPopup" Assembly="MyMainNamespace.SubNamespace.SelectorPopup" %>
[..]
<Selector:SelectorBoxControl runat="server" SelectorType="ContentArea" ></ Selector: SelectorBoxControl>

Our project is an ASP.NET web project on .NET 3.5 (2.0) deployed on IIS6 (Windows Server 2003) and we are using Sharepoint 2007, SQL Server 2005. Build, deploy and Visual Studio markup is fine.

Problem: After deploy to our test environment the user control is not displayed at all on the Sharepoint page and I can´t figure out why.

Build and deploy works fine and the Sharepoint page is even displayed, just that my control is nowhere to be seen. Actually, the HTML response contains absolutely no trace of my user control. Even if I put pure HTML text and no functionality in the control. There are no error messages and the event handler provides no information about possible errors or warnings.

Am I missing something? Is there anything I need to enable, an attribute I need to add or a reference somewhere? Is there anyway I can get this non-display behavior generate an understandable error message?

2
I'm venturing out of my comfort zone here, because I'm not a SharePoint wallah, but unless this changed in the last year, you can't use ASP.NET user controls - the kind that have markup in a separate .ascx file - in a web project other than the one they were created in. There are workarounds, though.Ann L.
I believe you are wrong here because actually, my task is to replace a third-party user control with similar functionality. This third-party control was used in Sharepoint and was located in a different assembly (DLL).Marcus
Well, that's one thing ruled out. :) Good luck!Ann L.
Actually, you got me thinking again. Is this a third-part control for which you have source? That has its own .ascx file? You might check the BuildAction on the .ascx file. There are some tricks you can play with Virtual Path Providers that allow you re-use User Controls with .ascx files in multiple projects. Perhaps those are being used. This (IIRC) involve the .ascx file being compiled as a resource.Ann L.
It is not a third-party control but a control I have implemented myself and there should be no restrictions on where it can be used.Marcus

2 Answers

0
votes

I think you need to register your dll with the GAC for SharePoint to find it. I could be wrong there though and copying to the bin dir does the trick. But I'm quite sure you need to user the fully qualified name in the Assembly attribute when registering.

<% @Register TagPrefix= "Selector" Namespace="MyMainNamespace.SubNamespace.SelectorPopup" Assembly="MyMainNamespace.SubNamespace.SelectorPopup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7fa78676161515a2" %>
0
votes

I'm posting this as an answer because, despite our exchange in comments, I'm not sure you and I have been talking about the same thing.

As you know, there are two kinds of controls in ASP.NET, user controls and web custom controls. User controls have an .ascx file containing markup and - this is important - can't be shared between projects. It does no good to compile the project they're in and reference that assembly, because the .ascx file is not part of the assembly. Web custom controls don't have a markup file: they are entirely created in code, with their controls being created programmatically and added to the Controls collection of the custom control.

So either the third party control in its separate assembly that you're replacing is a web custom control, or - if it uses a separate markup file in its source - it must be using a trick, such as the Virtual Path Provider trick, to achieve this.

You've talked about your user control and your code-behind as if they were separate things, which has led me to believe that you are indeed talking about a web user control. But these simply can't be shared between web projects. If your control needs to live in an external assembly, the simplest thing to do is re-write it as a custom control that builds its contents programmatically.

There are other options, such as the Virtual Path Provider solution, or a famous one from Scott Guthrie (here). But the least tricky option is to write it as a custom control.