[求助]一个用户自定义控件的问题
做的是注册系统 问题出在存在用户名的验证上先写代码 如下:
服务器端对自定义控件的验证代码:
Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
Dim name As String = args.Value
Dim objconn As New OleDbConnection
objconn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("mydb.mdb")
objconn.Open()
Dim sql As String = "select count(*) from lj where username='" & name & "'"
Dim objcmd As New OleDbCommand(sql, objconn)
Dim count As Integer = objcmd.ExecuteScalar
If count = 0 Then
args.IsValid = True
Else
args.IsValid = False
End If
objconn.Close()
End Sub
这是页面中的代码
<td width="187" style="width: 89px; height: 24px;">用户名:</td>
<td style="width: 661px; height: 24px;"><asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="username2" ControlToValidate ="username" runat="server" ErrorMessage="用户名不能为空" Width="110px" Display="Dynamic" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate ="username" ErrorMessage="该用户名已经存在" dispaly="dynamic"
OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
我把这两段同样的代码放在一个新页面中没有任何问题,在这个注册页面中还有其他密码 邮箱等其他验证 但就是当其他验证都通过后 输入已经存在的用户名还是没显示错误,很奇怪,高人指点下?