Both Page_PreRender
and Page_Load
do not work in the Master Page I am working with. Page_Init
does, however, for any reason. AutoEventWireup
is set to 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
}
}
I tried it out in an empty Web Project as well. There it works fine.
Edit: I figured out that setting EnableViewState
to true
fixes it:
<%@ Master Language="C#" MasterPageFile="~/MainMaster.master" AutoEventWireup="true"
CodeBehind="MyMaster.master.cs" Inherits="MyMaster" EnableViewState="false" %>
But I do not want the ViewState to be enabled. Overriding OnPreRender
works as well, no matter what value EnableViewState
has. Now I'm wondering why, and just using the override way seems a hacky to me. Can anybody help?
Page_Init
. – Taynatayra