简体   繁体   中英

Cant access user control after adding it in web.config

Added in web.config:

<pages>
  <controls>
    <add tagPrefix="dassier" src="~/App_Code/MapGrid.ascx" tagName="Map" />
  </controls>
</pages>

And then i try to call it from a .aspx page, and it doesnt work:

<dassier:Map ID="map1" runat="server"  />  

Anyone know why it would do this?

<dassier:Map ID="map1" runat="server"  /> 
</asp:Content>

Full page code:

<%@ Page Title="" Language="C#" MasterPageFile="Site.master" AutoEventWireup="true"
CodeFile="Map.aspx.cs" Inherits="Home" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="Server"> 

<dassier:Map ID="map1" runat="server"  /> 



</asp:Content>

You are trying to use App_Code for something it doesn't support.

From MSDN - Shared Code Folders in ASP.NET Web Projects :

User controls (ascx files) are not allowed in the App_Code folder. This includes single-file user controls and user controls that use the code-behind model. Putting a user control in the App_Code directory causes the user control's code to be compiled out of its required sequence and therefore is not allowed. (In any event, user controls do not need to be in the App_Code folder; they are already available to pages anywhere in the application.)

As the excerpt says, you don't need to put controls in App_Code - they are already available to pages, so long as they belong to the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM