Page_Load 事件

Page_Load 事件是众多 ASP.NET 可理解的事件之一。Page_Load 事件会在页面加载时被触发,然后 ASP.NET 会自动调用子例程 Page_Load
<%
@ Page Language="C#" AutoEventWireup="true" CodeBehind="DemoPage.aspx.cs" Inherits="WebApplication1.DemoPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="删除" /> </div> </form> </body> </html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class DemoPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //列表的绑定在第一次加载时有就可以了,点击删除,删除完成后会写绑定的代码
            //点击删除时执行这个Load事件的话不需要绑定.
            //触发页面的事件而造成再次请求这个页面的操作叫回传操作(如,点击删除)
            //判断页面是否是回传
            //Page 代表当前页面对象与this关键类似
            //Page.Response 接下来学习的很内置对象都 是Page对象的子对象

            if (Page.IsPostBack==false )
            {
                //this.IsPostBack
                Response.Write("绑定数据列表!!!<br/>"); 
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //删除
            Response.Write("删除成功!!<br/>");
            Response.Write("绑定数据列表!!<br/>");
        }
    }
}
原文地址:https://www.cnblogs.com/xiaz/p/5242481.html