本文共 1444 字,大约阅读时间需要 4 分钟。
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test4_2.WebForm1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title></head><body> <form id="form1" runat="server"> <div> 用户名:<asp:TextBox ID="txtName" runat="server" AutoPostBack="True" OnTextChanged="txtName_TextChanged"></asp:TextBox> <asp:Label ID="lblValidate" runat="server"></asp:Label><br /> 密码:<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox><br /> E-mail:<asp:TextBox ID="txtMail" runat="server" TextMode="Email"></asp:TextBox><br /> <asp:Button ID="btnSubmit" runat="server" Text="确认" /> </div> </form></body></html>
webform1.aspx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace test4_2{ public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { txtName.Focus(); } protected void txtName_TextChanged(object sender, EventArgs e) { if (txtName.Text == "admin") { lblValidate.Text = "此用户已存在"; } else { lblValidate.Text = "用户名可用"; } } }}
转载地址:http://gurm.baihongyu.com/