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?
I suggest to use
AutoEventWireupin the page directive, so would you please try as below:In your page directive
<%@ Page ..., useAutoEventWireup="true"and in your master page, removePreRenderevent subscription:Hope everything is fine now, thanks for your time.
Edit: Please check in your
web.configfile and ensure thatAutoEventWireupis not set toFalse.