views:

60

answers:

1

I have regular expression validation in a page which checks whether the entered value in the text box is a numeric, it is not numeric it gives error message says "it should be numeric"

but when i click on the next button of the form .. it navigates to the next page. But it shouldn't be. How to solve this?

 Protected Sub btn_View1_Next_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_View1_Next.Click
        Try
            Dim currentView As Int16
            currentView = mvRequestorForm.ActiveViewIndex
            Dim rowsCount As Integer = gvRoleDepartment.Rows.Count
            Dim checkCount As Integer = 0
            ''USERID Validation
            lblUserExists.Text = String.Empty

            rfvStoreNumber.Validate()
            rfvStoreNumber.SetFocusOnError = True

            rfvSurName.Validate()
            rfvSurName.SetFocusOnError = True

            ''New USesr
            If (ddl_view0_typeOfRequest.SelectedItem.ToString().ToLower().Equals("new")) Then
                rfvEmplyeeNumber.Visible = True
                If Page.IsValid Then
                    If currentView = 1 Then
                        mvRequestorForm.ActiveViewIndex = (currentView + 1)
                        rfv_view2_managersEmail.Enabled = True
                        rev_view2_managersEmail.Enabled = True
                    Else
                        mvRequestorForm.ActiveViewIndex = (currentView + 1)
                    End If

                    If currentView = 0 Then accountType = ddl_view0_typeOfRequest.SelectedItem.ToString()
                    If mvRequestorForm.ActiveViewIndex = 1 Then
                        Sub_ActivateView1()
                    End If
                End If
            ElseIf ddl_view0_typeOfRequest.SelectedValue.ToString().ToLower().Equals("delete") Then
                ''Check the requirement

                'rfvFirstName.Validate()
                'rfvFirstName.SetFocusOnError = True

                rfvUserID.Validate()
                rfvUserID.SetFocusOnError = True

                rfvEmplyeeNumber.Visible = True
                If Page.IsValid Then
                    Dim dsRoles As New DataSet
                    dsRoles = SearchGroups(txtUserID.Text.Trim())
                    If Not sResult Is Nothing Then
                        lblUserExists.Text = String.Empty
                        If currentView = 1 Then
                            mvRequestorForm.ActiveViewIndex = (currentView + 1)
                            rfv_view2_managersEmail.Enabled = True
                            rev_view2_managersEmail.Enabled = True
                        Else
                            mvRequestorForm.ActiveViewIndex = (currentView + 1)
                        End If

                        If currentView = 0 Then accountType = ddl_view0_typeOfRequest.SelectedItem.ToString()
                        If mvRequestorForm.ActiveViewIndex = 1 Then
                            Sub_ActivateView1()
                        End If
                    Else
                        lblUserExists.Text = String.Format("This userid doesn't exist. Please enter a valid user id.")
                        Return
                    End If
                End If
            Else
                ''Update User
                rfvUserID.Validate()
                rfvUserID.SetFocusOnError = True
                rfvEmplyeeNumber.Visible = True
                If Page.IsValid Then
                    Dim dsRoles As New DataSet
                    dsRoles = SearchGroups(txtUserID.Text.Trim())
                    If Not sResult Is Nothing Then
                        lblUserExists.Text = String.Empty
                        If currentView = 1 Then
                            mvRequestorForm.ActiveViewIndex = (currentView + 1)
                            rfv_view2_managersEmail.Enabled = True
                            rev_view2_managersEmail.Enabled = True
                        Else
                            mvRequestorForm.ActiveViewIndex = (currentView + 1)
                        End If

                        If currentView = 0 Then accountType = ddl_view0_typeOfRequest.SelectedItem.ToString()
                        If mvRequestorForm.ActiveViewIndex = 1 Then
                            Sub_ActivateView1()
                        End If
                    Else
                        lblUserExists.Text = String.Format("This userid doesn't exist. Please enter a valid user id.")
                        Return
                    End If
                End If
            End If

        Catch ex As Exception

        End Try
    End Sub
+1  A: 

First of all... Do you have this in your web.config:

<xhtmlConformance mode="Legacy">

If you do... this essentially breaks all client-side validation. It's important to note that server-side validation does not automatically keep your page from processing. You must check the Page.IsValid property... it looks like you're doing that. But...

Second... why are you explicitly calling Validate() on the rfvUserID control? This should not be necessary. It's possibly you are invalidating the IsValid property by doing this.

However, it sounds like the automatic validator is not firing. Can you post the aspx? Only validators in "Form2" validation group will fire for btn_View1_Next. Try removing ALL ValidationGroup settings. Does it work OK?

Finally... the id "Form2" implies something suspicious. You only have ONE actual form tag on this page, right? Otherwise you've got a whole host of problems.

Bryan
Problem with vaildation group ...rectified the issue