Guest User

Untitled

a guest
May 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. <asp:CheckBoxList RepeatDirection="Horizontal" RepeatLayout="Table" RepeatColumns="3" ID="ckBoxListReasons" runat="server">
  2. <asp:ListItem Text="Preliminary Construction" Value="prelim_construction" />
  3. <asp:ListItem Text="Final Construction" Value="final_construction" />
  4. <asp:ListItem Text="Construction Alteration" Value="construction_alteration" />
  5. <asp:ListItem Text="Remodel" Value="remodel" />
  6. <asp:ListItem Text="Color" Value="color" />
  7. <asp:ListItem Text="Brick" Value="brick" />
  8. <asp:ListItem Text="Exterior Lighting" Value="exterior_lighting" />
  9. <asp:ListItem Text="Deck/Patio/Flatwork" Value="deck_patio_flatwork" />
  10. <asp:ListItem Text="Fence/Screening" Value="fence_screening" />
  11. <asp:ListItem Text="Landscape - Front" Value="landscape_front" />
  12. <asp:ListItem Text="Landscape - Side/Rear" Value="landscape_side_rear" />
  13. <asp:ListItem Text="Other" Value="other" />
  14. </asp:CheckBoxList>
  15.  
  16. <asp:CheckBoxList ID="chkModuleList"runat="server" >
  17. </asp:CheckBoxList>
  18.  
  19. <asp:CustomValidator runat="server" ID="cvmodulelist"
  20. ClientValidationFunction="ValidateModuleList"
  21. ErrorMessage="Please Select Atleast one Module" ></asp:CustomValidator>
  22.  
  23. // javascript to add to your aspx page
  24. function ValidateModuleList(source, args)
  25. {
  26. var chkListModules= document.getElementById ('<%= chkModuleList.ClientID %>');
  27. var chkListinputs = chkListModules.getElementsByTagName("input");
  28. for (var i=0;i<chkListinputs .length;i++)
  29. {
  30. if (chkListinputs [i].checked)
  31. {
  32. args.IsValid = true;
  33. return;
  34. }
  35. }
  36. args.IsValid = false;
  37. }
  38.  
  39. function ValidateCheckBoxList(sender, args) {
  40. args.IsValid = false;
  41.  
  42. $("#" + sender.id).parent().find("table[id$="+sender.ControlId+"]").find(":checkbox").each(function () {
  43. if ($(this).attr("checked")) {
  44. args.IsValid = true;
  45. return;
  46. }
  47. });
  48. }
  49.  
  50. <asp:CheckBoxList runat="server"
  51. Id="cblOptions"
  52. DataTextField="Text"
  53. DataValueField="Id" />
  54.  
  55. <xx:CustomValidator Display="Dynamic"
  56. runat="server"
  57. ID="cblOptionsValidator"
  58. ControlId="cblOptions"
  59. ClientValidationFunction="ValidateCheckBoxList"
  60. ErrorMessage="One selection required." />
  61.  
  62. public class CustomValidator : System.Web.UI.WebControls.CustomValidator
  63. {
  64. public string ControlId { get; set; }
  65.  
  66. protected override void OnLoad(EventArgs e)
  67. {
  68. if (Enabled)
  69. Page.ClientScript.RegisterExpandoAttribute(ClientID, "ControlId", ControlId);
  70.  
  71. base.OnLoad(e);
  72. }
  73. }
  74.  
  75. Dim bolSelectionMade As Boolean = False
  76. For Each item As ListItem in ckBoxListReasons.Items
  77. If item.Selected = True Then
  78. bolSelectionMade = True
  79. End If
  80. Next
Add Comment
Please, Sign In to add comment