Radio Button Validation in a .aspx file?

Rate It (1)

Last post 04-18-2007 1:53 PM by kalvagadda. 14 replies.

Sort Posts:

  • Radio Button Validation in a .aspx file?

    04-12-2007, 5:47 PM
    • Loading...
    • xberserker
    • Joined on 11-17-2005, 10:30 PM
    • Posts 51

    Below are the radio buttons are that I want to validate.

    I would like to display some red text under the radio buttons like the rest of the validation is doing. Or if that's not possible just a alert box would work as well. Any thoughts? Confused  

    https://www.ucreditu.com/forms/jobapplication_test.aspx

                     'Determine radio selection for referral source
                    Dim referralMsg As String = "Referral Source: "
                    If referral1.Checked = True Then
                        referralMsg = referralMsg & referral1.Text
                    ElseIf referral2.Checked = True Then
                        referralMsg = referralMsg & referral2.Text
                    ElseIf referral3.Checked = True Then
                        referralMsg = referralMsg & referral3.Text
                    ElseIf referral4.Checked = True Then
                        referralMsg = referralMsg & referral4.Text
                    ElseIf referral5.Checked = True Then
                        referralMsg = referralMsg & referral5.Text & ": " & employeeName.Text
                    ElseIf referral6.Checked = True Then
                        referralMsg = referralMsg & referral6.Text & ": " & other.Text
                    End If
                    lblReferral.Text = referralMsg

     

    <td colspan="3"><asp:Label ID="lblReferral" runat="server" Text="Referral Source"></asp:Label>
    <br />
    <asp:RadioButton ID="referral1" runat="server" Text="Advertisement" GroupName="referral" />
    <asp:RadioButton ID="referral2" runat="server" Text="Employment Agency" GroupName="referral" />
    <asp:RadioButton ID="referral3" runat="server" Text="Walk-In" GroupName="referral" />
    <asp:RadioButton ID="referral4" runat="server" Text="Relative" GroupName="referral" />
    <br />
    <asp:RadioButton ID="referral5" runat="server" Text="Employee" GroupName="referral" />
    (name:
    <asp:TextBox ID="employeeName" runat="server" Width="100px" style="width:100px"></asp:TextBox>
    )
    <asp:RadioButton ID="referral6" runat="server" Text="Other" GroupName="referral" />
    <asp:TextBox ID="other" runat="server" Width="100px" style="width:100px"></asp:TextBox>

     

    Beware the spinning triangles of death!!
  • Re: Radio Button Validation in a .aspx file?

    04-13-2007, 10:56 AM
    There is no out of box validator but you can always use custom validator. you can find several examples on web.
    Don't forget to click "Mark as Answer" on the post that helped you.
  • Re: Radio Button Validation in a .aspx file?

    04-13-2007, 12:28 PM
    • Loading...
    • xberserker
    • Joined on 11-17-2005, 10:30 PM
    • Posts 51
    I've been looking and I haven't found anything that works Crying
    Beware the spinning triangles of death!!
  • Re: Radio Button Validation in a .aspx file?

    04-13-2007, 12:34 PM
    Answer

    ok then. you can always use requiredfieldvalidator with radiobuttonlist.

            <asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="76px" RepeatDirection="Horizontal"
                Style="z-index: 103; left: 20px; position: absolute; top: 164px" Width="56px">
                <asp:ListItem>One</asp:ListItem>
                <asp:ListItem>Two</asp:ListItem>
                <asp:ListItem>Three</asp:ListItem>
                <asp:ListItem>Four</asp:ListItem>
                <asp:ListItem>Five</asp:ListItem>
            </asp:RadioButtonList>

            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="RadioButtonList1"
                ErrorMessage="RequiredFieldValidator" Style="z-index: 107; left: 24px; position: absolute;
                top: 256px">Please Select Radio Button</asp:RequiredFieldValidator>
     

    Don't forget to click "Mark as Answer" on the post that helped you.
  • Re: Radio Button Validation in a .aspx file?

    04-13-2007, 2:45 PM
    • Loading...
    • xberserker
    • Joined on 11-17-2005, 10:30 PM
    • Posts 51

    The code you provided does work Smile , I modified it a little.

            <asp:RadioButtonList ID="RadioButtonList1" runat="server" Height="76px" RepeatDirection="Horizontal">
                <asp:ListItem Text="Advertisement">Advertisement</asp:ListItem>
                <asp:ListItem Text="Employment Agency">Employment Agency</asp:ListItem>
                <asp:ListItem Text="Walk-In">Walk-In</asp:ListItem>
                <asp:ListItem Text="Relative">Relative</asp:ListItem>
                <asp:ListItem Text="Employee">Employee</asp:ListItem>
                <asp:ListItem Text="Other">Other</asp:ListItem>           
            </asp:RadioButtonList>

            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="RadioButtonList1"
                ErrorMessage="RequiredFieldValidator">Please Select a Referral Source</asp:RequiredFieldValidator>

    But I can't get to work with this code. And this code basically creates a variable so I can put it into a e-mail.

                    'Determine radio selection for referral source
    Dim referralMsg As String = "Referral Source: "
    If RadioButtonList1.Checked = True Then
    referralMsg = referralMsg & RadioButtonList1.Text
    ElseIf RadioButtonList1.Checked = True Then
    referralMsg = referralMsg & RadioButtonList1.Text
    ElseIf RadioButtonList1.Checked = True Then
    referralMsg = referralMsg & RadioButtonList1.Text
    ElseIf RadioButtonList1.Checked = True Then
    referralMsg = referralMsg & RadioButtonList1.Text
    ElseIf RadioButtonList1.Checked = True Then
    referralMsg = referralMsg & RadioButtonList1.Text & ": " & employeeName.Text
    ElseIf RadioButtonList1.Checked = True Then
    referralMsg = referralMsg & RadioButtonList1.Text & ": " & other.Text
    End If
    lblReferral.Text = referralMsg 
    This is the ERROR Message Crying

    Server Error in '/' Application.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30456: 'Checked' is not a member of 'System.Web.UI.WebControls.RadioButtonList'.

    Source Error:


    Line 15:                 'Determine radio selection for referral source
    Line 16: Dim referralMsg As String = "Referral Source: "
    Line 17: If RadioButtonList1.Checked = True Then
    Line 18: referralMsg = referralMsg & RadioButtonList1.Text
    Line 19: ElseIf RadioButtonList1.Checked = True Then

    Source File: d:\inetpub\wwwroot\forms\jobapplication_test.aspx    Line: 17