前兩天在做一個用戶注冊,在用戶名處增加了驗證用戶名是否存在的功能,需要在用戶輸入用戶名時利用Button激活的事件來判斷,但是注冊的其他TextBox控件又為了防止為空使用了RequiredFIEldValidator控件進行驗證。代碼如下:
Html代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="buttonValidate.ASPx.cs" Inherits="buttonValidate" %>
<Html XMLns="http://www.w3.org/1999/xHtml" >
<head runat="server">
<title>無標題頁</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ASP:TextBox ID="TextBox1" runat="server"></ASP:TextBox>
<ASP:RequiredFIEldValidator ID="RequiredFIEldValidator1" runat="server" ErrorMessage="*" ControlToValidate="TextBox1"></ASP:RequiredFIEldValidator>
<ASP:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="檢查" CausesValidation="False" /><br />
<br />
<ASP:TextBox ID="TextBox2" runat="server"></ASP:TextBox>
<ASP:RequiredFIEldValidator ID="RequiredFIEldValidator2" runat="server" ErrorMessage="*" ControlToValidate="TextBox2"></ASP:RequiredFIEldValidator><br />
<br />
<ASP:TextBox ID="TextBox3" runat="server"></ASP:TextBox>
<ASP:RequiredFIEldValidator ID="RequiredFIEldValidator3" runat="server" ErrorMessage="*" ControlToValidate="TextBox3"></ASP:RequiredFIEldValidator><br />
<br />
<ASP:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" /><br />
<br />
<ASP:Label ID="Label1" runat="server" Height="139px" Text="Label" Width="272px"></ASP:Label></div>
</form>
</body>
</Html>