0
大家好我是動態創建CheckBox控件,我想申請一個驗證檢查,這是我的示例代碼我如何申請自定義驗證用於動態創建的複選框,並自定義驗證
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);
}
燦有人幫我