Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <asp:CheckBoxList RepeatDirection="Horizontal" RepeatLayout="Table" RepeatColumns="3" ID="ckBoxListReasons" runat="server">
- <asp:ListItem Text="Preliminary Construction" Value="prelim_construction" />
- <asp:ListItem Text="Final Construction" Value="final_construction" />
- <asp:ListItem Text="Construction Alteration" Value="construction_alteration" />
- <asp:ListItem Text="Remodel" Value="remodel" />
- <asp:ListItem Text="Color" Value="color" />
- <asp:ListItem Text="Brick" Value="brick" />
- <asp:ListItem Text="Exterior Lighting" Value="exterior_lighting" />
- <asp:ListItem Text="Deck/Patio/Flatwork" Value="deck_patio_flatwork" />
- <asp:ListItem Text="Fence/Screening" Value="fence_screening" />
- <asp:ListItem Text="Landscape - Front" Value="landscape_front" />
- <asp:ListItem Text="Landscape - Side/Rear" Value="landscape_side_rear" />
- <asp:ListItem Text="Other" Value="other" />
- </asp:CheckBoxList>
- <asp:CheckBoxList ID="chkModuleList"runat="server" >
- </asp:CheckBoxList>
- <asp:CustomValidator runat="server" ID="cvmodulelist"
- ClientValidationFunction="ValidateModuleList"
- ErrorMessage="Please Select Atleast one Module" ></asp:CustomValidator>
- // javascript to add to your aspx page
- function ValidateModuleList(source, args)
- {
- var chkListModules= document.getElementById ('<%= chkModuleList.ClientID %>');
- var chkListinputs = chkListModules.getElementsByTagName("input");
- for (var i=0;i<chkListinputs .length;i++)
- {
- if (chkListinputs [i].checked)
- {
- args.IsValid = true;
- return;
- }
- }
- args.IsValid = false;
- }
- function ValidateCheckBoxList(sender, args) {
- args.IsValid = false;
- $("#" + sender.id).parent().find("table[id$="+sender.ControlId+"]").find(":checkbox").each(function () {
- if ($(this).attr("checked")) {
- args.IsValid = true;
- return;
- }
- });
- }
- <asp:CheckBoxList runat="server"
- Id="cblOptions"
- DataTextField="Text"
- DataValueField="Id" />
- <xx:CustomValidator Display="Dynamic"
- runat="server"
- ID="cblOptionsValidator"
- ControlId="cblOptions"
- ClientValidationFunction="ValidateCheckBoxList"
- ErrorMessage="One selection required." />
- public class CustomValidator : System.Web.UI.WebControls.CustomValidator
- {
- public string ControlId { get; set; }
- protected override void OnLoad(EventArgs e)
- {
- if (Enabled)
- Page.ClientScript.RegisterExpandoAttribute(ClientID, "ControlId", ControlId);
- base.OnLoad(e);
- }
- }
- Dim bolSelectionMade As Boolean = False
- For Each item As ListItem in ckBoxListReasons.Items
- If item.Selected = True Then
- bolSelectionMade = True
- End If
- Next
Add Comment
Please, Sign In to add comment