du kan gøre det på denne måde: <asp:CheckBox runat="server" ID="chk" /> <asp:RequiredFieldValidator ID="chrReq" runat="server" SetFocusOnError="true" ControlToValidate="chk" EnableClientScript="true" ErrorMessage="Du skal vælge lala"></asp:RequiredFieldValidator> <asp:ValidationSummary ID="valsum" runat="server" ShowMessageBox="true" EnableClientScript="true" HeaderText="Følgende fejl opstod" /> <asp:LinkButton runat="server" CausesValidation="true" ID="lala"></asp:LinkButton>
Min fejl. Du kan lave en custom control der kan gøre det for dig: using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel;
namespace CustomValidators { public class RequiredFieldValidatorForCheckBoxLists : System.Web.UI.WebControls.BaseValidator { private ListControl _listctrl;
public RequiredFieldValidatorForCheckBoxLists() { base.EnableClientScript = false; }
protected override bool ControlPropertiesValid() { Control ctrl = FindControl(ControlToValidate);
<script language="javascript"> function ClientValidation(source, args) { args.IsValid = document.getElementById("ckTerms").checked; if(!args.IsValid) { alert('du skal trykke i checkboxen'); } } </script>
<asp:Checkbox id="ckTerms" runat="server" /> I agree to the terms. <asp:CustomValidator id="CustomValidator1" ErrorMessage="*Required" ClientValidationFunction="ClientValidation" runat="server" />
Du skal bare indsætte <script language="javascript"> function ClientValidation(source, args) { args.IsValid = document.getElementById("ckTerms").checked; if(!args.IsValid) { alert('du skal trykke i checkboxen'); } } </script> i starten af siden
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.