Added in web.config:
<pages>
<controls>
<add tagPrefix="dassier" src="~/开发者_StackOverflow社区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.
精彩评论