日期:2011-07-13 浏览次数:20651 次
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 />
<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 />
<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 />
<asp:Button ID="btnLogin" runat="server" Text="登录" />
<asp:Button ID="btnClear" runat="server" Text="清空" />
<asp:Button ID="btnClose" runat="server" Text="关闭" /><br />
<br />
<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中添加