我不明白AutoEventWireUp页面属性负责什么.
在网上冲浪时,我发现很多论坛都有关于它的讨论,它们对我来说都显得有些不一致.
我能否清楚解释这个属性究竟意味着什么?
我已经阅读了这篇文章,但即使我不理解.
如何使用Global.asax 的PostAuthenticateRequest事件?我正在关注本教程并提到我必须使用PostAuthenticateRequest事件.当我添加Global.asax事件时,它创建了两个文件,标记和代码隐藏文件.这是代码隐藏文件的内容
using System;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
namespace authentication
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{ …Run Code Online (Sandbox Code Playgroud) 双方Page_PreRender并Page_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
}
}
Run Code Online (Sandbox Code Playgroud)
我也在一个空Web项目中尝试过.它工作得很好.
编辑:我想通了,设置EnableViewState以true修复它:
<%@ Master Language="C#" MasterPageFile="~/MainMaster.master" AutoEventWireup="true"
CodeBehind="MyMaster.master.cs" Inherits="MyMaster" EnableViewState="false" %>
Run Code Online (Sandbox Code Playgroud)
但我不希望启用ViewState.OnPreRender无论有什么价值,压倒一切EnableViewState都是有效的.现在我想知道为什么,只是使用覆盖方式对我来说似乎是个hacky.有人可以帮忙吗?