Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

asp.net - Master property is not auto generated in aspx designer causing runtime errors

I have a content page that uses a MasterPageFile, and in the code we try to access a master property Master.SessionId.

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminFrontend.Master" AutoEventWireup="true"
    CodeBehind="Reasons.aspx.cs" Inherits="Admin.Other.Reasons" %>

<asp:Content ID="Content2" ContentPlaceHolderID="cphMainBody" runat="server">
    <reason session-id="<%=Master.SessionId%>">
    </reason>
</asp:Content>

But the Master.SessionId is not recognized, Master is not referring to the correct master file. Similar code works on another file within the project. The only notable difference that we found is that the page that works has the following auto-generated code in the aspx.designer.cs file.

public partial class MyChart {
        
        /// <summary>
        /// Master property.
        /// </summary>
        /// <remarks>
        /// Auto-generated property.
        /// </remarks>
        public new Admin.AdminFrontend Master {
            get {
                return ((Admin.AdminFrontend)(base.Master));
            }
        }
    }

This is the designer for my Reasons.aspx file.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated. 
// </auto-generated>
//------------------------------------------------------------------------------

namespace Admin.Other
{


    public partial class Reasons
    {
    }
}

I am not sure what is the problem, why in one file that property is auto-generated and not in the other. I thought Visual Studio is doing something crazy. I restarted VS2019 and also tried restarting my machine. Both didn't solve the 

problem.

question from:https://stackoverflow.com/questions/65924391/master-property-is-not-auto-generated-in-aspx-designer-causing-runtime-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There may not even 'be' a Designer page for the "Reasons.aspx.cs". Please check to ensure it exists for the Reasons.aspx page (open the Solution Explorer and view the associated to the Reason.aspx file). If the Designer file does not exist, select/highlight the Reason.aspx file in the Solution Explorer, then use the upper menu bar (in Visual Studio), and choose the Project > Convert to Web Application selection. If that selection is missing from the Projects pulldown menu, this typically indicates all Designer files are connected to your CodeBehind files.

If you do have a Reasons.aspx.designer.cs, please provide the code here so we can compare it to the one from your MyChart example.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...