大家好,我正在动态创建一个复选框控件,我想应用验证来检查这是我的示例代码
public void custom()
{
CheckBox chkID = new CheckBox();
chkID.ID = "chkID1";
CustomValidator cus = new CustomValidator();
cus.ValidationGroup = "vg";
cus.ErrorMessage = "Required";
string sID = chkID.ClientID;
StringBuilder strScript = new StringBuilder();
strScript.Append("<script type=\"text/javascript\">");
strScript.Append("function ValidateCheckBox(sender, args) {");
strScript.Append("if(document.getElementById('" + sID + "').Checked==true");
strScript.Append("{");
strScript.Append("args.IsValid=true;}");
strScript.Append("else{");
strScript.Append("args.IsValid=false;}}");
cus.ClientValidationFunction = strScript.ToString();
plcHolder.Controls.Add(chkID);
plcHolder.Controls.Add(cus);
}
有人能帮我吗