簡體   English   中英

ASP.NET母版頁中的PreRender未觸發

[英]PreRender in ASP.NET Master Page not firing

Page_PreRenderPage_Load都不能在我正在使用的母版頁中工作。 但是, Page_Init出於任何原因。 AutoEventWireup設置為true。

public partial class MyMaster : MasterPage
{
    public MyMaster()
    {
        // tried this too, but doesn't matter whether this LoC
        // is there or not
        this.PreRender += Page_PreRender;
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        // does not fire
    }
}

我也在一個空的Web項目中嘗試過。 它工作得很好。

編輯:我發現設置EnableViewStatetrue修復它:

<%@ Master Language="C#" MasterPageFile="~/MainMaster.master" AutoEventWireup="true"
    CodeBehind="MyMaster.master.cs" Inherits="MyMaster" EnableViewState="false" %>

但我不希望啟用ViewState。 無論EnableViewState具有什么值,重寫OnPreRender可以正常工作。 現在我想知道為什么,只是使用覆蓋方式對我來說似乎是個hacky。 有人可以幫忙嗎?

我建議在頁面指令中使用AutoEventWireup ,所以請嘗試如下:

在您的頁面指令<%@ Page ... ,使用AutoEventWireup="true"並在您的母版頁中刪除PreRender事件訂閱:

public MyMaster()
{
    // tried this too, but doesn't matter whether this LoC
    // is there or not
    //this.PreRender += Page_PreRender;
}

希望現在一切都很好,謝謝你的時間。

編輯:請檢入您的web.config文件並確保AutoEventWireup未設置為False

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM