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 ...
随机推荐
- Window脚本学习笔记之BAT简介
本篇文章不是直接讲技术,而是对我自己学习这些年来的一番感触和简单的介绍,其间也穿插着一些基本的知识,若是学习技术者可跳过,亦不妨碍学习其他. BAT简介 BAT是Windows的批处理脚本,即以后缀“ ...
- 能用的单纯形法python代码
网上找了一些代码,发现有一些是不能用的,出现错误说集合为空 1.网上出现了好多次,但是不能用的,只能部分模型能用,比如例子中所示 原链接:https://www.jianshu.com/p/b233c ...
- TreadPool
ThreadPool概述 提供一个线程池,该线程池可用于执行任务.发送工作项.处理异步 I/O.代表其他线程等待以及处理计时器. 创建线程需要时间.如果有不同的小任务要完成,就可以事先创建许多线程/在 ...
- [唐胡璐]Selenium技巧- Prop.Properties配置测试应用的环境和其他配置项
prop.propertiesfile contains important info that needs to be changed before the test is run, such a ...
- DevExpress Winforms使用大揭秘!那些你不了解的SvgImageBox控件
DevExpress Winforms Controls 内置140多个UI控件和库,完美构建流畅.美观且易于使用的应用程序.无论是Office风格的界面,还是分析处理大批量的业务数据,DevExpr ...
- MySQL添加foreign key时出现1215 Cannot add the foreign key constraint
引言: MySQL中经常会需要创建父子表之间的约束,这个约束是需要建立在主外键基础之上的,这里解决了一个在创建主外键约束过程中碰到的一个问题. mysql中添加外键约束遇到一下情况: cannot a ...
- dblclick([[data],fn]) 当双击元素时,会发生 dblclick 事件。
dblclick([[data],fn]) 概述 当双击元素时,会发生 dblclick 事件.大理石量具哪家好 当鼠标指针停留在元素上方,然后按下并松开鼠标左键时,就会发生一次 click.在很短的 ...
- Django-中间件实现1分钟内只允许三次访问
代码 class Throttle(MiddlewareMixin): def process_request(self, request): # 1. 拿到用户请求的IP # print(reque ...
- 【线性代数】5-2:置换和余因子(Permutations and Cofactors)
title: [线性代数]5-2:置换和余因子(Permutations and Cofactors) categories: Mathematic Linear Algebra keywords: ...
- 解决“cv2.error: OpenCV(3.4.2) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:356:...”
主要是图片路径中“文件夹分隔符”使用的错误 将“\”改成“/”就好了 修改后的测试代码如下:x.py #导入cv模块 import cv2 as cv #读取图像,支持 bmp.jpg.png.tif ...