dynamic validations for checkboxlist and dropdownlist

Discussion in 'Software' started by mrugesh_dulera, Jun 26, 2007.

  1. mrugesh_dulera


    Jun 26, 2007
    Likes Received:
    hi everybody,

    1) I am creating a form dynamically so all the controls like textbox, label, dropdownlist are created dynamically according to the values in the database.

    2) I am also assigning values to this controls dynamically while page is loaded from the values in database.

    3) I am also using masters page, content place holder

    Following is my aspx file....

    <%@ Page Language="VB" MasterPageFile="~/TemplateAssets/Inside.master" AutoEventWireup="false" CodeFile="FormHandler.aspx.vb" Inherits="Forms_FormHandler" %>

    <asp:Content ID="FormContentFrame" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:placeHolder runat="server" id="FormPlaceHolder" />
    <asp:HiddenField ID="HiddenFormID" runat="server" />
    <asp:HiddenField ID="HiddenRespondentGUID" runat="server" />
    <div align="right" style="padding-top:10px;">

    <asp:CompareValidator ID="CompValDate" type="Date" Operator="DataTypeCheck" runat="server"></asp:CompareValidator>
    <asp:CompareValidator ID="CompValCurrency" type="Currency" Operator="DataTypeCheck" runat="server"></asp:CompareValidator>
    <asp:CompareValidator ID="CompValFloat" type="Double" Operator="DataTypeCheck" runat="server"></asp:CompareValidator>
    <asp:CustomValidator runat="server" ID="ValCheckBoxList" ClientValidationFunction="isChecked()"></asp:CustomValidator>&nbsp;
    <asp:Button ID="Val" runat="server" Text="Validate" OnClick="valcheckbox"/>&nbsp;
    <asp:TextBox ID="testing" runat="server" />
    <asp:Button ID="SubmitButton" runat="server" Text="Submit" CssClass="SubmitButton" />


    Following is my code behind file for creating dynamic controls and assigning values to it from database..

    snap of code:-

    Case "CheckBoxList"
    'LHS Column
    Dim r As New TableRow()
    Dim c As New TableCell()
    Dim Label As New Label
    Label.Text = record.Item("Label")
    c.VerticalAlign = VerticalAlign.Top
    'RHS Column
    c = New TableCell()
    Dim CheckboxList As New CheckBoxList
    Dim ResponseOptions As String = record.Item("ResponseOptions").ToString
    Dim ResponseOptionsArray As String() = Nothing

    ResponseOptionsArray = ResponseOptions.Split(",")
    CheckboxList.ID = record.Item("FieldGUID")
    Dim ResponseOption As String
    For Each ResponseOption In ResponseOptionsArray

    Next ResponseOption
    CheckboxList.SelectedIndex = 0
    CheckboxList.ID = "checkboxlist"
    l2.Text = "Please Select One Of The CheckBox :- "

    3)--- And I am creating sub pro ( onclick the validation should fire )

    Public Sub valcheckbox(ByVal sender As Object, ByVal e As System.EventArgs) Handles Val.Click

    l3.Text = "hello000000000000000000"
    l2.Text = " hello2000000000000000"
    testing.Text = "hello300000000000000000000"

    'Dim userSelectionList As CheckBoxList = CType(FindControl("checkboxlist"), CheckBoxList)

    'If userSelectionList.SelectedIndex = -1 Then
    ' l1.Text = "Please Select One Of The Option In CheckBoxList "
    'End If

    'Dim userSelectionList2 As DropDownList = CType(FindControl("dropdownlist"), DropDownList)

    'If userSelectionList2.SelectedIndex = 0 Then
    ' l2.Text = "Please Select Any Item Other Then -Select- "
    'End If

    End Sub

    ----->4) The main program is when i click on button it doesnt get fire it simply can't display label testing,l2,l3 just first line in the sub proce

    so i dont think its getting side ..?

    Also can any one please check my logic for validation dyamic is proper or not..? beacause all data and controls are created dynamic ..?

    Thanking you all....
    mrugesh_dulera, Jun 26, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.