我目前引用this網站進行AD角色管理。將masterpage添加到aspx網頁
的C#代碼工作正常,但是當我與母版一起粘貼我的網頁裏面的代碼,頁面給了我該說的錯誤:
Content controls have to be top-level controls in a content page or a nested master page that references a master page.
可我知道我應該怎麼設置我的主頁在這種情況下?
.aspx頁面中無母版:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
string[] rolesArray;
MembershipUserCollection users;
string[] usersInRole;
public void Page_Load()
{
....
}
public void AddUsers_OnClick(object sender, EventArgs args)
{
....
}
public void UsersInRoleGrid_RemoveFromRole(object sender, GridViewCommandEventArgs args)
{
....
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Sample: Role Membership</title>
</head>
<body>
<form runat="server" id="PageForm">
<font face="helvetica" size="6" color="#455c75"><strong>Role Membership</strong></font><font face="helvetica" size="5" color="#455c75"><strong> Management</strong></font>
<br /><asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
<table cellpadding="3" border="0">
...
</table>
</form>
母版:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MainPage.master.cs" Inherits="MainPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>SOD</title>
<link href="Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
...
</body>
</html>
編輯:
我試着插入MasterPageFile="~/MainPage.master"
進入第一變量,與開始我的.aspx頁面中<%@ Page Language="C#" MasterPageFile="~/MainPage.master"%>
,給我上面提到的錯誤。
請張貼 - .master和.aspx頁面的標記。 – adatapost
@AVD我已更新我的帖子 – gymcode
您的帖子對我而言並不明確。請在一行中說「你想做什麼?」如果您想以編程方式配置母版頁,請閱讀以下鏈接:http://www.asp.net/web-forms/tutorials/master-pages/specifying-the-master-page-programmatically-vb和http:// msdn .microsoft.com/en-us/library/ie/c8y19k6h.aspx – adatapost