zoukankan      html  css  js  c++  java
  • 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 = 0;
        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 == 0)
            {
                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, 1);
    
     // 登录跳转到成功页面
     if (loginMsg == string.Empty)
     {
         LoginLog();
         Response.Redirect(strSuccessUrl);
     }
  • 相关阅读:
    浅谈观察者设计模式
    关于如何成为专家(1)
    微信小程序 PHP后端form表单提交实例详解
    mysql中的union和order by、limit
    SQL的各种连接(cross join、inner join、full join)的用法理解
    mysql数据库创建、删除数据库
    PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP 未声明(在此函数内第一次使用) 规格严格
    TroubleshootingGuide for JavaTM SE 6withHotSpot TM VM (翻译附录未完待续) 规格严格
    关闭URLClassLoader打开的jar包 规格严格
    两个长度分析【POST|GET】 规格严格
  • 原文地址:https://www.cnblogs.com/wolfocme110/p/4173182.html
Copyright © 2011-2022 走看看