ASP.Net Make Form Validation occur after selectedindexchange

Posted on 2011-05-12
Last Modified: 2012-05-11
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
Question by:jshesek
    LVL 4

    Accepted 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

    LVL 30

    Expert Comment

    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)
    LVL 12

    Expert Comment

    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?
    LVL 1

    Author Comment

    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

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now