6

両方ともPage_PreRenderPage_Load私が使用しているマスターページでは機能しません。Page_Initただし、何らかの理由で実行します。AutoEventWireuptrueに設定されています。

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プロジェクトでも試してみました。そこでは正常に動作します。

EnableViewState編集:私はそれをtrue修正するためにその設定を理解しました:

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

しかし、ViewStateを有効にしたくありません。OnPreRender値が何であっても、オーバーライドも同様に機能しEnableViewStateます。今、私はなぜだろうと思っています、そしてオーバーライド方法を使用するだけで私にはハッキーに思えます。誰か助けてもらえますか?

4

1 に答える 1

-1

page ディレクティブで使用することをお勧めし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

于 2011-12-08T12:59:12.870 に答える