Page_Load事件

Page_Load事件---IsPostBack属性 

aspx代码

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 style="text-align: left">
        
<br />
        
<br />
        
<br />
        
<br />
        
&nbsp; &nbsp;&nbsp;
        
<asp:Label ID="Label1" runat="server" Height="31px" Text="用户名:" Width="95px"></asp:Label>
        
<asp:TextBox ID="textUserName" runat="server" Height="24px" OnTextChanged="textUserName_TextChanged">textUserName</asp:TextBox><br />
        
&nbsp; &nbsp; &nbsp;<asp:Label ID="Label2" runat="server" Height="29px" Text="密码:"
            Width
="93px"></asp:Label>
        
<asp:TextBox ID="textUserPwd" runat="server" Height="22px">textUserPwd</asp:TextBox>
        
<br />
        
<br />
        
&nbsp; &nbsp;&nbsp;
        
<asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" Text="登录" />
        
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        
<asp:Button ID="btnClear" runat="server" OnClick="btnClear_Click" Text="清空" />
        
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        
<asp:Button ID="btnClose" runat="server" Text="关闭" /><br />
        
<br />
        
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        
<asp:Label ID="lblMessage" runat="server" Height="66px" Text=" " Width="175px"></asp:Label></div>
    
</form>
</body>
</html>

aspx.cs代码

 

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!Page.IsPostBack) //判断页面是否是第一次加载
        {
            
this.textUserName.Text= " ";  //将用户名框设置为空
            this.textUserPwd.Text= " ";  //将密码框设置为空
        }

        
this.btnClose.Attributes.Add("onclick""window.close();");//关闭按纽设置,相当于在aspx文件的asp:label中添加onclick="window.close();"
    }


    
protected void btnLogin_Click(object sender, EventArgs e)
    
{
        
if (this.textUserName.Text == "zuo" && this.textUserPwd.Text == "zuo")
        
{
            
this.lblMessage.Text = "登录成功";
        }

        
else
        
{
            
this.lblMessage.Text = "登陆失败";
        }

    }

    
protected void btnClear_Click(object sender, EventArgs e)
    
{
        
this.textUserName.Text = " ";  //设置为空
        this.textUserPwd.Text = " ";  //设置为空
    }

}

posted @ 2007-04-12 00:18  ermen  阅读(136)  评论(0)    收藏  举报