我有一个使用MasterPageFile
的内容页面,并且在代码中我们尝试访问一个主属性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>
但Master.SessionId
无法识别,主文件引用的主文件不正确。类似的代码适用于项目中的另一个文件。我们发现唯一值得注意的区别是,正常工作的页面在aspx.designer.cs文件中具有以下自动生成的代码。
public partial class MyChart {
/// <summary>
/// Master property.
/// </summary>
/// <remarks>
/// Auto-generated property.
/// </remarks>
public new Admin.AdminFrontend Master {
get {
return ((Admin.AdminFrontend)(base.Master));
}
}
}
这是我的Reasons.aspx文件的设计器。
//------------------------------------------------------------------------------
// <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
问题来了。
发布于 2021-01-27 17:50:52
甚至可能没有"Reasons.aspx.cs“的设计器页面。请检查以确保它存在于Reasons.aspx页面(打开解决方案资源管理器并查看与Reason.aspx文件相关联的)。如果设计器文件不存在,请在解决方案资源管理器中选择/突出显示Reason.aspx文件,然后使用上部菜单栏(在Visual Studio中),并选择项目> Convert to Web Application选项。如果项目下拉菜单中缺少该选项,则通常表示所有设计器文件都已连接到CodeBehind文件。
如果您有Reasons.aspx.designer.cs,请在此处提供代码,以便我们可以将其与您的MyChart示例中的代码进行比较。
发布于 2021-01-27 18:06:03
在Reasons.aspx.cs文件中,您可以添加公共属性并返回Master.sessionID。
例如:
public partial class MyChart
{
public string MySession
{
get
{
return Master.SessionID;
}
}
}
在aspx文件中,使用
<reason session-id="<%=MySession%>"></reason>
https://stackoverflow.com/questions/65924391
复制相似问题