主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:210次

Page_Load事件---IsPostBack属性

aspx代码

 

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



    无标题页


   


   
       

       

       

       

            
       
        textUserName

                         Width="93px">
        textUserPwd
       

       

            
       
                
       
                 
       

       

                 
        <>
   

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 = " ";  //设置为空
    }
}

 

<> <>
关键字词: