Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 25th, 2007, 09:00 PM
Registered User
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamic validation for checkboxlist and other

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....

Old June 27th, 2007, 05:44 AM
Registered User
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

When u use master pages u cannot call directly the control by id since it is been place in the content holder.....
So try using some other mechanism to dynamically add validation for that control


Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckboxList onselectindexchanged rlb ASP.NET 2.0 Professional 1 August 13th, 2008 12:56 PM
Checkboxlist epkgupta Visual Studio 2005 0 March 11th, 2008 05:31 AM
CheckBoxList stu9820 ASP.NET 1.0 and 1.1 Basics 10 May 25th, 2006 08:15 PM
CheckBoxList eddiema VS.NET 2002/2003 1 April 9th, 2004 09:49 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.