help with this code

cocol

Active member
Joined
Jul 23, 2010
Messages
30
Programming Experience
Beginner
hello!
i need help with this code.
so the problem is that i want to hide or remove the message of the custom validator when the required validator worked,so if you try this code you will see that when you type 3 characters in the textbox in the top ="txtUserName" and then move the mouse or "tab" to the second textbox ,then an autopostback happened so a message from the custom validator appeared ,so then delete these 3 characters and tab to the next textbox so you see my problem that the old message of the custom validator remain and the message of the required field validator appeared (*),so i tried everything i can and no success so i believe that if i can override the function of the required field validator that i add customvalidator1.text="" so i can success.
and this is the code:
VB.NET:
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
          <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
          <ContentTemplate>
              <asp:table ID="Table1" runat="server" >
                     <asp:TableRow runat="server"><asp:TableCell RowSpan="3" runat="server">
                         <asp:TextBox ID="txtUserName" runat="server" AutoPostBack="True" CausesValidation="True"></asp:TextBox>
                        
                      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="txtUserName" >*</asp:RequiredFieldValidator>
                     
 <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ControlToValidate="txtUserName" EnableClientScript="False" OnServerValidate="CustomValidator1_ServerValidate" ValidateEmptyText="false" EnableViewState="false" Display="Dynamic" SetFocusOnError="false" EnableTheming="true"></asp:CustomValidator>
                        
                        </asp:TableCell>
                   </asp:TableRow>
                     </asp:table>
 </ContentTemplate>
          </asp:UpdatePanel>
       
        </div>
    </form>
</body>






Imports System.IO
Imports System.Security.Permissions

Partial Class _Default
    Inherits System.Web.UI.Page



    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        
       
        If Char.IsDigit(args.Value.Chars(0)) Then
            args.IsValid = False
            Image1.Visible = False
            CustomValidator1.Text = "The First caracter must be a char"
        Else
            If args.Value.Length < 4 And args.Value.Length <> 0 Then
                args.IsValid = False
                Image1.Visible = False
                CustomValidator1.Text = "User Name must be at least 4 caracteres"

' i tried this by removing the required field validator and in the property of the 'custom validator:validateemptytext=true,but no success
                'Else
                '    If args.Value.Length = 0 Then    
                '        CustomValidator1.Text = "*"
                '        args.IsValid = False

                '    End If
            End If
        End If

    End Sub

and i tried enableviewstate=false for the customvalidator and no success no please i need your experiences and help.
so if you sign up in a new hotmail account then in the field "hotmail account" at the top is what i need for example type a wrong hotmail or existing for example "d" ,then tab to the next textbox so i message will appear,then clear the first textbox and tab again to the other so another message appear.
so i need your help and i prefer an example for resolving my problem.
thank you very much :).
 

Latest posts

Back
Top