locked
Validate CheckBoxList on the registration page RRS feed

  • Question

  • Hi!

    This code:

    Imports Microsoft.VisualBasic

    Namespace CustomListValidator ''' <summary> ''' Summary description for ListValidator ''' </summary> Public Class ListValidator Inherits BaseValidator Public Sub New() End Sub Protected Overrides Function ControlPropertiesValid() As Boolean Dim ctrl As Control = TryCast(FindControl(ControlToValidate), ListControl) Return (Not ctrl Is Nothing) End Function Protected Overrides Function EvaluateIsValid() As Boolean Return Me.CheckIfItemsIsChecked() End Function Protected Function CheckIfItemsIsChecked() As Boolean Dim listItemValidate As ListControl = (CType(Me.FindControl(Me.ControlToValidate), ListControl)) For Each listItem As ListItem In listItemValidate.Items If listItem.Selected = True Then Return True End If Next listItem Return False End Function End Class End Namespace

    designed to validate CheckBoxList control, works on the ordinary pages, but does not work on the registration page.

    Here is my registration page:

                                   
    <%@ Page Title="Register" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
        CodeFile="Register.aspx.vb" Inherits="Account_Register" %>
        <%@ Register TagPrefix="CLV" Namespace="CustomListValidator" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false">
            <LayoutTemplate>
                <asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
                <asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
            </LayoutTemplate>
            <WizardSteps>
                <asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
                    <ContentTemplate>
                        <h2>
                            Create a New Account
                        </h2>
                        <p>
                            Use the form below to create a new account.<br />
                            Passwords are required to be a minimum of <%= Membership.MinRequiredPasswordLength %> characters in length.
                        </p>
                        <%--<span class="failureNotification">
                            <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
                        </span>
                        <asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"
                             ValidationGroup="RegisterUserValidationGroup"/>--%>


                        <div class="accountInfo">
                            <fieldset class="register">
                                <legend>Account Information</legend>
    <%--Here are the usual fields--%>
                                

                                <br />
                                    <asp:Label ID="LabLanguage" runat="server"></asp:Label><br />
                                    <CLV:ListValidator ID="custLstVal" ControlToValidate="UserLanguage" Display="Dynamic"
                                ErrorMessage="At least one item in the checkboxlist chould be checked" ValidationGroup="RegisterUserValidationGroup"
                                runat="server" ToolTip="At least one item in the checkboxlist chould be checked"></CLV:ListValidator>

                                    <asp:CheckBoxList ID="UserLanguage" RepeatColumns="4" RepeatLayout="Table"
                                    RepeatDirection="Horizontal" runat="server" AppendDataBoundItems="False" AutoPostBack="False" CausesValidation="False">
                                        <asp:ListItem Value="ar">Arabic</asp:ListItem>
                                        <asp:ListItem Value="bg">Bulgarian</asp:ListItem>
                                        <asp:ListItem Value="ca">Catalan</asp:ListItem>
                                        <asp:ListItem Value="zh-CHS">Chinese (Simplified)</asp:ListItem>
                                        <asp:ListItem Value="zh-CHT">Chinese (Traditional)</asp:ListItem>
                                        <asp:ListItem Value="cs">Czech</asp:ListItem>
                                        <asp:ListItem Value="da">Danish</asp:ListItem>
                                        <asp:ListItem Value="nl">Dutch</asp:ListItem>
                                        <asp:ListItem Value="en">English</asp:ListItem>
                                        <asp:ListItem Value="et">Estonian</asp:ListItem>
                                        <asp:ListItem Value="fi">Finnish</asp:ListItem>
                                        <asp:ListItem Value="fr">French</asp:ListItem>
                                        <asp:ListItem Value="de">German</asp:ListItem>
                                        <asp:ListItem Value="el">Greek</asp:ListItem>
                                        <asp:ListItem Value="ht">Haitian Creole</asp:ListItem>
                                        <asp:ListItem Value="he">Hebrew</asp:ListItem>
                                        <asp:ListItem Value="hi">Hindi</asp:ListItem>
                                        <asp:ListItem Value="hu">Hungarian</asp:ListItem>
                                        <asp:ListItem Value="id">Indonesian</asp:ListItem>
                                        <asp:ListItem Value="it">Italian</asp:ListItem>
                                        <asp:ListItem Value="ja">Japanese</asp:ListItem>
                                        <asp:ListItem Value="ko">Korean</asp:ListItem>
                                        <asp:ListItem Value="lv">Latvian</asp:ListItem>
                                        <asp:ListItem Value="lt">Lithuanian</asp:ListItem>
                                        <asp:ListItem Value="mww">Hmong Daw</asp:ListItem>
                                        <asp:ListItem Value="no">Norwegian</asp:ListItem>
                                        <asp:ListItem Value="pl">Polish</asp:ListItem>
                                        <asp:ListItem Value="pt">Portuguese</asp:ListItem>
                                        <asp:ListItem Value="ro">Romanian</asp:ListItem>
                                        <asp:ListItem Value="ru">Russian</asp:ListItem>
                                        <asp:ListItem Value="sk">Slovak</asp:ListItem>
                                        <asp:ListItem Value="sl">Slovenian</asp:ListItem>
                                        <asp:ListItem Value="es">Spanish</asp:ListItem>
                                        <asp:ListItem Value="sv">Swedish</asp:ListItem>
                                        <asp:ListItem Value="th">Thai</asp:ListItem>
                                        <asp:ListItem Value="tr">Turkish</asp:ListItem>
                                        <asp:ListItem Value="uk">Ukrainian</asp:ListItem>
                                        <asp:ListItem Value="vi">Vietnamese</asp:ListItem>
                                    </asp:CheckBoxList>
                            </fieldset>
                            <p class="submitButton">
                                <asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User"
                                     ValidationGroup="RegisterUserValidationGroup"/>
                            </p>
                        </div>
                    </ContentTemplate>
                    <CustomNavigationTemplate>
                    </CustomNavigationTemplate>
                </asp:CreateUserWizardStep>
            </WizardSteps>
        </asp:CreateUserWizard>
    </asp:Content>

    Please tell me, what I need to change in the code.

    Saturday, May 19, 2012 9:49 PM

Answers

  • Hi,

    From your code, your question is more related to http://forums.asp.net/. Please post your question there for better support.

    Our forum is for Visual Studio Express installation.

    Best regards,


    Barry Wang [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Mr. Wharty Thursday, May 31, 2012 12:19 AM
    • Marked as answer by Mr. Wharty Thursday, June 7, 2012 2:53 AM
    Monday, May 21, 2012 8:37 AM