我试图在我的Page.LoadComplete事件 ASP.NET解决方案(.NET Framework4.5.2)中连接Master.Page。
我想我应该测试一下,看看事件是否已经设置好了:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
if (Page.LoadComplete == null) {
Page.LoadComplete += new EventHandler(Page_LoadCompleted);
}
}
}但是Visual不会编译。它给出了这个错误:
CS0079:事件'Page.LoadComplete‘只能出现在+=或-=的左侧:

我尝试添加一个布尔值来检查此代码的状态:
private bool loadCompleteSet;
protected void Page_Load(object sender, EventArgs e)
{
if (!loadCompleteSet) {
Page.LoadComplete += new EventHandler(Page_LoadCompleted);
loadCompleteSet = true;
}
}但是,当Visual再次设置值时,它会抛出一个错误:
Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Type: System.Web.HttpUnhandledException
Stack Trace: at System.Web.UI.Page.HandleError(Exception e) at
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at
System.Web.UI.Page.ProcessRequest() at
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at
System.Web.UI.Page.ProcessRequest(HttpContext context) at
ASP.procedures_instance_procedureinstanceoverview_aspx.ProcessRequest(HttpContext context) in c:\Users\jp2code\AppData\Local\Temp\Temporary ASP.NET Files\vs\57369bc8\785f0aba\App_Web_procedureinstanceoverview.aspx.efa023fc.ponfm23d.0.cs:line 0 at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)它提到了这个临时文件夹:
C:\User\jp2code\AppData\Local\Temp\ ASP.NET临时ASP.NET 0
我已经关闭了Visual并删除了上面引用的临时文件夹,但是只要我重新启动Visual,它就会重新创建。
临时文件夹引用一个App_Web_procedureinstanceoverview.aspx页面。该项目确实有一个负责注册控件的ProcedureInstanceOverview.aspx文件,但它没有引用我正在运行的页面。
我如何连接我的Page.LoadComplete事件?
发布于 2021-01-06 15:40:01
我添加了一个Page_Init部分,在那里插入了我的LoadComplete代码,而且我没有出现任何错误。
protected void Page_Init(object sender, EventArgs e)
{
Page.LoadComplete += Page_LoadComplete;
}很简单。
https://stackoverflow.com/questions/65585985
复制相似问题