首页 > 开发 > 综合 > 正文

Page_Load事件

2024-07-21 02:26:04
字体:
来源:转载
供稿:网友

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 >
        <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中添加
    }

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

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表