开发者

ASP.NET master page not executing

I have a master page, and a content page.

The master page however doesn't appear to be executing any of the PageLoad code that I have defined.

In addition, when I built my application I did not get any errors or warnings.

Here is my master admin page:

<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
    1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="mainHead" runat="server" >
        <title>Administration</title>
        <link rel="Stylesheet" href="../style/admin.css" />       
    </head>
    <body>

    <form id="mainForm" runat="server">

    <div class="topMenu">    

        <asp:Panel id="mnu0" runat="server" CssClass="navButton">
            <a href="admin.aspx?mid=0" class="navLink">Admin Home</a>
        </asp:Panel>

        <asp:Panel id="mnu1" runat="server" CssClass="navButton">
            <a href="admin.aspx?mid=1" class="navLink">User Manager</a>
        </asp:Panel>

        <asp:Panel id="mnu2" runat="server" CssClass="navButton">
            <a href="admin.aspx?mid=2" class="navLink">Products</a>
        </asp:Panel>  

        <asp:Panel id="mnu3" runat="server" CssClass="navButtonR">
            <a href="../default.aspx" class="navLink">Back to Site</a>
        </asp:Panel>
    </div>

    <br /><br />
    <asp:Panel id="subLinks" runat="server" CssClass="subMenu"></asp:Panel>

    <div class="mainContent">
        <asp:contentplaceholder id="mainContent" runat="server" />
    </div>



    </form>
    </body>
</html>

It's code behind:

using System;
using System.Collections.Generic;
using 开发者_JAVA百科System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace AlphaPackSite.MasterPages
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        protected int menuID;

        protected void Page_Load(object sender, EventArgs e)
        {
            string menuIDdata = Page.Request.QueryString["mid"];
            menuID = 0;

            // Check the user is allowed here
            if (!Roles.IsUserInRole("Admin"))
            {
                Response.Redirect("../default.aspx");
            }

            // Get the menu ID
            if (!int.TryParse(menuIDdata, out menuID))
            {
                menuID = 0;
            }

            // Select the correct menu
            var selectedMenu = this.Page.FindControl("mnu" + menuID) as Panel;
            selectedMenu.CssClass = "navButtonO";

            // Admin menu
            if (menuID == 0)
            {
                subLinks.Controls.Add(new HyperLink { Text = "Admin Home", NavigateUrl = "admin.aspx", CssClass = "subLink" });
                subLinks.Controls.Add(new HyperLink { Text = "Site Settings", NavigateUrl = "siteSettings.aspx", CssClass = "subLink" });
            }
            // User manager
            else if (menuID == 1)
            {

            }
            // Products
            else if (menuID == 2)
            {
                subLinks.Controls.Add(new HyperLink { Text = "Product Categories", NavigateUrl = "productCats.aspx", CssClass = "subLink" });
                subLinks.Controls.Add(new HyperLink { Text = "Organise Products", NavigateUrl = "productOrg.aspx", CssClass = "subLink" });
                subLinks.Controls.Add(new HyperLink { Text = "Add Product", NavigateUrl = "productAdd.aspx", CssClass = "subLink" });
                subLinks.Controls.Add(new HyperLink { Text = "Modify Products", NavigateUrl = "productChange.aspx", CssClass = "subLink" });
            }
        }  
    }
}

The content page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="admin.aspx.cs" Inherits="AlphaPackSite.admin"
    title="Hi there!"
    MasterPageFile="../MasterPages/Admin.master"
%>
<asp:content id="Content1" contentplaceholderid="mainContent" runat="server">

lol this is the admin page

</asp:content>

Content displays as expected, but none of the menu links display when they did when the code was all on a seperate page.

Any ideas?


Codefile="Admin.master.cs"

Check this out!!


<%@ Master Language="C#" %>

should be more like :

<%@ Master Language="C#" CodeFile="Admin.master.cs" Inherits="Admin" %>

since there is no link between the page and the code-behind that's why nothing executes.


You need the AutoEventWireup="true" and CodeFile="file.master.cs" attributes to appear in the definition of your master page as well.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Admin.master.cs" Inherits="Admin" %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜