Monday, December 20, 2010

SmartPart - unable to load ~\/UserControls\CustomControl.aspx in SharePoint. Could not load CustomControl.ascx


We had an issue with one of the custom controls hosted by the SmartPart (with AJAX).

The issue was:
  • A custom control was deployed to the "UserControls" folder under the portal's virtual directory.
  • Then a page was created and "SmartPart with AJAX" added to it.
  • In the SmaprtPart's properties section, under "User control to display:" drop-down it displayed "Could not load CustomControl.ascx".
  • I still selected the custom control from the drop-down and clicked on OK.
  • The control was added, but there was an error message
    Error: unable to load ~\/UserControls\CustomControl.ascx
    Details: c:\Inetpub\wwwroot\wss\VirtualDirectories\portal80\UserControls\CustomControl.ascx(6):
    error CS0023: Operator '--' cannot be applied to operand of type 'void'.
The cause of this error was the server-side comments section in the .ascx file:
<%--
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //This control is not used in other environments.
-- %>  

 As soon as this section was removed from the .ascx file, both the errors disappeared.The control appeared without errors in the drop-down and rendered fine on the page.