1

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?

Marcus
  • 8,230
  • 11
  • 61
  • 88
  • 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. Oct 01 '12 at 22:08
  • 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 Oct 02 '12 at 08:04
  • 1
    Well, that's one thing ruled out. :) Good luck! – Ann L. Oct 02 '12 at 12:18
  • 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. Oct 03 '12 at 13:43
  • 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 Oct 04 '12 at 08:08

2 Answers2

0

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" %>
Ioana O
  • 197
  • 1
  • 10
  • Unfortunately that does not do the trick for me. The output assembly is already located in the bin folder and when I remove it from there I get an exception upon loading the page telling me that the assembly is missing. I tried to use the fully qualified name in the assembly attribute but still nothing... – Marcus Oct 02 '12 at 06:35
  • if bin does not work, then you probably need to add the dll to GAC like so: http://www.thespgeek.com/2010/11/how-to-add-dll-to-gac-in-windows-7.html and add it to the package as a dependency in Package.package at the bottom there is an Advanced tab:http://stackoverflow.com/questions/5092544/deploying-custom-dlls-in-sharepoint-2010 – Ioana O Oct 02 '12 at 10:27
  • Put it into GAC, recycled application pool and restarted IIS but still nothing. – Marcus Oct 02 '12 at 14:09
  • I'm sorry, that's how far my SharePoint expertise goes, I have only 6 mo experience :( Good luck finding your answer! Maybe you can find someone faster on http://sharepoint.stackexchange.com/ – Ioana O Oct 04 '12 at 08:27
0

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.

Ann L.
  • 13,760
  • 5
  • 35
  • 66
  • I am talking about a regular ASP.NET ascx control. We have another assembly with several user controls (ascx) that are deployed directly into the ControlTemplates folder of our Sharepoint solution. The DLL is loaded into Sharepoint and that works just fine. My problem is that I wanted to create a new assembly with a similar approach, although in my DLL I also have aspx pages opened from within the user control. Unfortunately I haven´t found any good solution in time and I have abandoned the idea for a different solution. – Marcus Oct 09 '12 at 11:02
  • I realize this has since died in conversation. Just wanted to show this article showing that ascx is possible to share accross assemblies. https://msdn.microsoft.com/en-us/library/aa479318.aspx – Jimmie Clark Feb 26 '18 at 20:54