CustomValidator-Check Char Length

Results 1 to 2 of 2

Thread: CustomValidator-Check Char Length

  1. #1
    Join Date
    Dec 1969

    Default CustomValidator-Check Char Length

    I am facing a problem to validate a textbox tat not allow user to input more than 20 chars. And at the same time i also check tat if the input that the user key in is match with the database. if do, return false. I follow the books instruction and type in exactly the same.. but the validator is not function. i wondering y... can anyone help the poor little boy here? <BR><BR><BR>Private Sub VarUserLeng_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles VarUserLeng.ServerValidate<BR> &#039;args.IsValid = (args.Value.Length &#060;= 20)<BR> If Len(args.Value) &#060;= 20 Then<BR> args.IsValid = True<BR> Else<BR> args.IsValid = False<BR> End If<BR>End Sub<BR><BR> Sub CheckUserName(ByVal sender As System.Object, ByVal args As ServerValidateEventArgs)<BR> Dim UserNameString As String = txbUserName.Text<BR> Dim objReader As OleDbDataReader<BR> Dim objConnection As New OleDbConnection(Application("SQLConnectionString") )<BR> Dim sqlstring As String = "select cust_UserName from customer where cust_UserName = &#039;" & UserNameString & "&#039;"<BR><BR> &#039;Response.Write(sqlstring)<BR> &#039;Response.End()<BR><BR> Dim objCmd As New OleDbCommand(sqlstring, objConnection)<BR><BR> objConnection.Open()<BR> objReader = objCmd.ExecuteReader()<BR><BR> While objReader.Read()<BR> Dim UserName As String<BR> UserName = objReader.GetString(0)<BR> Response.Write(UserName)<BR> Response.End()<BR> If UserName = "" Then<BR> args.IsValid = True<BR> Else<BR> args.IsValid = False<BR> End If<BR> End While<BR>End Sub<BR><BR>&#060;asp:customvalidator ID="VarUserLeng" runat="server" Display="Dynamic" ControlToValidate="txbUserName" CssClass="validator" ErrorMessage="UserName cannot be more than 20 characters"&#062;&#060;/asp:customvalidator&#062;<BR>&#060;asp:customvalid ator id="ValUserExist" CssClass="validator" ErrorMessage="UserName already exits. Please choose another" Display="Dynamic" ControlToValidate="txbUserName" Runat="server" OnServerValidate="CheckUserName"&#062;&#060;/asp:customvalidator&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: CustomValidator-Check Char Length

    tzeyik:<BR><BR>Get rid of the CustomValidator for this. Theres no need for it! Just set the MaxLength property of your textbox to 20 and youll never have to worry about validating it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts