• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 413
  • Last Modified:

ASP.Net Make Form Validation occur after selectedindexchange

I have a page that has 2 radio buttons Myself & Someone else. (Radiobutton List)  
When the user clicks on a Myself some textbox fields fill in with their info.  (The info comes from a cookie)  
When the user clicks on Someone else those textbox fields clear.  
There is also Form Validation on the radio button list and textboxes.  
The problem comes in when I click on Myself - the validation kicks in before the textboxes can fill in.  If I then click on a textbox - type a letter then click out of the textbox my info fills in.
Anyway to get the validation to fire off after the text boxes fill in?

Here's the code:
On the .aspx page

<asp:RequiredFieldValidator ID="vldRequestor" runat="server"
              ControlToValidate="requestor" ErrorMessage="Please choose myself or someone else."
              Display="Dynamic" SetFocusOnError="True"></asp:RequiredFieldValidator>&nbsp;
        <asp:RadioButtonList runat="server" ID="requestor" RepeatDirection="Horizontal"
              Width="325px" Height="18px" CausesValidation="True"
              OnSelectedIndexChanged="requestor_SelectedIndexChanged" AutoPostBack="True">
          <asp:ListItem Value="me" Text="Myself"></asp:ListItem>
          <asp:ListItem Value="you" Text="Someone else"></asp:ListItem>

On the aspx.vb page:

 Protected Sub requestor_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles requestor.SelectedIndexChanged
        lbl3.Text = "here"

       If (requestor.Items(0).Selected) Then
            empName.Text = (Request.Cookies("FirstName").Value + " " + Request.Cookies("LastName").Value)
            job.Text = Request.Cookies("Job").Value
            area.Text = Request.Cookies("Area").Value
            email.Text = Request.Cookies("email").Value
            phone.Text = Request.Cookies("phone").Value

        End If
        If (requestor.Items(1).Selected) Then
            lbl3.Text = "you"
            empName.Text = ""
            job.Text = ""
            area.Text = ""
            email.Text = ""
            phone.Text = ""

        End If
    End Sub
1 Solution
To disallow the validation from happening on changing the RadioButton, set its property:
 CausesValidation = "false"

Open in new window

requestor.CausesValidation = false;

Open in new window


This can be done in the .aspx or in the PageLoad in .aspx.vb

And in the CodeBehind (.aspx.vb) file, add the following code to cause validation after data is filled in the textboxes.

Open in new window

If you want to do this in client side code call Page_ClientValidate(). It returns true if the page was valid. If you are using ASP.NET 2.0, pass the validation group name as a parameter (Page_ClientValidate("") will handle when there is no group name.) You can call this function from an onclick event handler on the dropdown (i.e. HTML SELECT)
your question is not clear for me. what type of validations you want to do?
you placed a required field validator to compulsory select one of the radiobutton. but it is not necessary as we cannot uncheck the all radio buttons in the form. every time one of the radio button is having checked state.

Can you please elaborate your problem some more extent?
jshesekAuthor Commented:
Hey jagssidurala - This form is a request for help.  The people who respond to it want to know if the request is from the person who entered it or is it for someone else?  Like a boss asking for software for their employee or an employee asking for access to files in a certain area.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now