OnPreInit,OnInit ,OnInitComplete ,OnPreLoad ,Page_Load等执行顺序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class Default5 : System.Web.UI.Page
{
static int count = ;
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(count + "Page_Load <br />");
count++;
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
Response.Write(count + "OnPreInit <br />");
count++;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Response.Write(count + "OnInit <br />");
count++;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Response.Write(count + "OnLoad <br />");
count++;
}
protected override void OnPreLoad(EventArgs e)
{
base.OnPreLoad(e);
Response.Write(count + "OnPreLoad <br />");
count++;
}
protected override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
Response.Write(count + "OnLoadComplete <br />");
count++;
}
protected override void OnInitComplete(EventArgs e)
{
base.OnInitComplete(e);
Response.Write(count + "OnInitComplete <br />");
count++;
}
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
Response.Write(count + "OnDataBinding <br />");
count++;
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
Response.Write(count + "OnPreRender <br />");
count++;
}
protected void btnGraphics_Click(object sender, EventArgs e)
{
//Bitmap bmp = new Bitmap(10, 10);
//Graphics g = Graphics.FromImage(bmp);
Response.Write(count + "btnGraphics_Click <br />");
count++;
} }
结果为:
0OnPreInit
1OnInit
2OnInitComplete
3OnPreLoad
4Page_Load
5OnLoad
6OnLoadComplete
7OnPreRender
*session失效或者超时的跳转(站长后台)
判断页面(每个页面调用)
protected override void OnPreInit(EventArgs e)
{
new Users().GetUserInfoCookie(out _mywebhostid, out _myuserid);
if (_myuserid == string.Empty || _mywebhostid == )
{
Response.Redirect("~/login.aspx?reurl=" + HttpUtility.UrlEncode(Request.Url.AbsoluteUri));
}
else
{
new Users().GetUserInfoCookie(out _mywebhostid, out _myuserid);
}
base.OnPreInit(e);
}
登录页面
string strIp = Request.UserHostAddress;
string strSuccessUrl = Request.QueryString["reurl"] == null ? "~/index.aspx" : HttpUtility.UrlDecode(Request.QueryString["reurl"].ToString()); Users u = new Users();
string loginMsg = u.LoginMsg(strUserId, strPassword, Request.UserHostAddress);
u.LoginMsg2(strUserId, Request.UserHostAddress, Request.UserAgent, ); // 登录跳转到成功页面
if (loginMsg == string.Empty)
{
LoginLog();
Response.Redirect(strSuccessUrl);
}
OnPreInit,OnInit ,OnInitComplete ,OnPreLoad ,Page_Load等执行顺序的更多相关文章
- aspx页面Page_Load和aspx页面上控件Page_Load事件执行顺序
今天公司的同事问了我一个问题,就是页面的Load方法和控件上的Load方法执行顺序的问题,看完了这个图片的递归调用之后大家就笑了,吼吼.
- ASP.NET Page执行顺序
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- .NET页面事件执行顺序
摘自:http://www.cnblogs.com/kenkofox/archive/2011/03/18/1987998.html和http://blog.csdn.net/yiruoyun/art ...
- .NET Page页面事件执行顺序,以及其作用(OnPreInit()、OnInit()等)
以按钮事件为测试标准 1. OnPreInit //检查 IsPostBack 属性来确定是不是第一次处理该页. //创建或重新创建动态控件. //动态设置主控页. //动态设置 Theme 属性. ...
- ASP.NET Page执行顺序如:OnPreInit()、OnInit()
http://www.cnblogs.com/yeminglong/archive/2012/10/16/2725664.html 当页面进行回发时,如点击按钮,以上事件都会重新执行一次,这时的执行顺 ...
- ASP.NET Page执行顺序如:OnPreInit()、OnInit()……
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security ...
- asp.net OnInit、OnLoad、Page_Load、Page_Init父子页面执行顺序探究
本次探究page页面加载的时候,它们的执行顺序 BasePage public class BasePage : Page { public string BaseName { get; set; } ...
- 运行page页面时的事件执行顺序
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- 转:运行page页面时的事件执行顺序及页面的回发与否深度了解
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
随机推荐
- 18 Candidates for the Top 10 Algorithms in Data Mining
Classification============== #1. C4.5 Quinlan, J. R. 1993. C4.5: Programs for Machine Learning.Morga ...
- win服务器 解决apache 80端口被占用问题
是系统的服务占用了80端口,所以要么结束系统服务,要么修改apache端口. PID4的服务是World Wide Web Publishing Service 这里选择结束这个系统服务,运行serv ...
- webclient上传下载文件
定义WebClient使用的操作类: 操作类名称WebUpDown WebClient上传文件至Ftp服务: //// <summary> /// WebClient上传文件至Ftp服务 ...
- 2019HDU多校Path——最短路最小割
题目 给出一个 $n$ 个顶点 $m$ 条边的图,要求阻塞一些边,使得从 $1$ 到 $n$ 的最短路变长,求阻塞的边长度和的最小值,不必保证阻塞后可达. 分析 很显然,要阻塞的边肯定在最短路图上,先 ...
- python自动华 (六)
Python自动化 [第六篇]:Python基础-面向对象 目录: 面向过程VS面向对象 面向对象编程介绍 为什么要用面向对象进行开发 面向对象的特性:封装.继承.多态 面向过程 VS 面向对象 ...
- IIS上传限制大小
加入下面的配置即可 <?xml version="1.0" encoding="UTF-8"?> <configuration> < ...
- BZOJ 3679 数字之积 数位DP
思路:数位DP 提交:\(2\)次 错因:进行下一层\(dfs\)时的状态转移出错 题解: 还是记忆化搜索就行,但是要用\(map\)记忆化. 见代码 #include<cstdio> # ...
- web批量下载文件到本地
JavaWeb 文件下载功能 文件下载的实质就是文件拷贝,将文件从服务器端拷贝到浏览器端,所以文件下载需要IO技术将服务器端的文件读取到,然后写到response缓冲区中,然后再下载到个人客户端. 1 ...
- [Luogu] LCA
https://www.luogu.org/problemnew/show/P4211 baoli #include <iostream> #include <cstdio> ...
- 重读APUE(10)-中断的系统调用
如果进程在执行一个低速系统调用而阻塞期间捕获到一个信号,则该系统调用就会被中断而不再继续执行:该系统调用返回出错,其errno设置为EINTR: 系统将系统调用分成两类:低速系统调用和其他系统调用:低 ...