ascx user control when it's been registered on

2019-08-14 19:44发布

问题:

Hi I've registered a user control on the top of an appx control.

<%@ Register Src="../Controls/Attachments.ascx" TagName="Attachments" TagPrefix="uc7" %>
<%@ Register Src="../Controls/Help.ascx" TagName="Help" TagPrefix="uc8" %>
<%@ Register Src="~/Controls/WRControls/WRDetails.ascx" TagName="WR" TagPrefix="uc9"  %>

Unfortunately when I try to call the new user control. i.e

"<uc9:WR" (uc9:WR does not appear in the ittelisense drop down) for the new user control which I've added.

The base user control is under a different file path to other user controls. As you can see above.

As i'm unable to find the user control in the intellisense I can then not add the control to the aspx page.

I've tried all sorts onthe base control i.e deleting all code in the designer.cs page then cutting and re-pasting the html to re-generate the designer.cs page all to no avail.

回答1:

Register your user control in the web.config file as shown in this article:

http://weblogs.asp.net/scottgu/archive/2006/11/26/tip-trick-how-to-register-user-controls-and-custom-controls-in-web-config.aspx

Under <pages> in the web.config file, add a <controls> block as follows:

<?xml version="1.0"?>

<configuration>

  <system.web>

    <pages>
      <controls>
        <add tagPrefix="scottgu" src="~/Controls/Header.ascx" tagName="header"/>
        <add tagPrefix="scottgu" src="~/Controls/Footer.ascx" tagName="footer"/>
        <add tagPrefix="ControlVendor" assembly="ControlVendorAssembly"/>
      </controls>
    </pages>

  </system.web>

</configuration>