开发者

Nested Master Pages in ASP.NET results in missing controls!

开发者 https://www.devze.com 2023-02-25 03:53 出处:网络
I have the following Hierarchy: MainMasterPage: <%@ Master Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"MainAdmin.master.cs\" Inherits=\"MyWebsite.Admin.MainAdmin\" %>

I have the following Hierarchy:

MainMasterPage:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MainAdmin.master.cs" Inherits="MyWebsite.Admin.MainAdmin" %>

<form id="form1" runat="server">
<div id="MainMenu_Div" runat="server">
    <asp:ContentPlaceHolder ID="MainMenu" runat="server"/>
</div>

<div id="ContentArea_Div" runat="server">
    <asp:ContentPlaceHolder ID="ContentArea" runat="server"/>
</div>
</form>

TemplateMasterPage:

<%@ Master Language="C#" MasterPageFile="~/Admin/MasterPages/MainAdmin.Master" AutoEventWireup="true" CodeBehind="TemplateMasterPage.master.cs" Inherits="MyWebsite.Admin.TemplateMasterPage" %>

<asp:Content ID="ContentArea" ContentPlaceHolderID="ContentArea" runat="server">
    <div id="InputControls_Div" runat="server">
        <asp:ContentPlaceHolder ID="InputControls" runat="server" />
        <br />
        <asp:Button ID="Submit_Btn" runat="server" Text="Submit" 
            onclick="Submit_Btn_Click" />
    </div>


    <div id="AfterSubmission_Div" runat="server" visible="False">
    <asp:Button ID="AnotherBtn" runat="server" CssClass="linkLookingButton" 
        onclick="AnotherBtn_Click" />
    </div>
</asp:Content>

TemplateMasterPage (Code Behind)

public partial class TemplateMasterPage : System.Web.UI.MasterPage
{
    public string BtnText
    {
        get { return AnotherBtn.Text; } //AnotherBtndoesn't exist in the current context
        set { AnotherBtn.Text = value; } //AnotherBtndoesn't exist in the current context
    }


    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Submit_Btn_Click(object sende开发者_Go百科r, EventArgs e)
    {
        Submit_Btn.Enabled = false; //Submit_Btn doesn't exist in the current context

        InputControls_Div.Visible = false; //InputControls_Div doesn't exist in the current context
        AfterSubmission_Div.Visible = true; //AfterSubmission_Div doesn't exist in the current context
    }

I commented the errors in my Code Behind sample .. this is used to work before using Nested Master Pages!


Just built a website based on your code fragments.

Some thoughts on it:

  • Your class is named TemplatePage in code behind but refered as TemplateMasterPage.
  • There is no control AnotherBtn. There is Submit_Btn only.
  • There is no control Btn. There is Submit_Btn only.
  • I get no errors on InputControls_Div or AfterSubmission_Div.

So all I can say, that your compiler is right and you have to add the missing buttons or rename the code to make it compile successfully.

0

精彩评论

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