谁有做地验证CheckBoxList的CustomerValidator,最好是通用的

如果有代码的话立刻给分
[11 byte] By [bobowu-bobo] at [2008-2-16]
# 1
你这个是自己写进去的,怎么还需要去验证它

如果你需要用户单独输入的话还不如在输入的时候进行验证
# 2
private void cvaTelNumberFormat_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if(isTelNumber(this.txtTelNumber.Text.ToString().Trim()))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}

}

这是服务器端验证

function ValidateInfoOriginLength(source, args)
{

if((Trim(document.getElementById(source.controltovalidate).value) != '')
&& (IsLength(Trim(document.getElementById(source.controltovalidate).value), 120)) )
{ args.IsValid = true;}
else
{ args.IsValid = false;}
}
客户端验证
chiyuwang-chiyuwang at 2007-11-1 > top of Msdn China Tech,.NET技术,ASP.NET...
# 3
就是验证至少要选择其中一个啊,要怎么样写啊
bobowu-bobo at 2007-11-1 > top of Msdn China Tech,.NET技术,ASP.NET...
# 4
用JS在客户端验证

function CheckedCount()
{ var flag=0;
try
{

var mm = document.getElementsByTagName("input").length ;
for(var i=0;i<mm;i++)
{
var dd = document.getElementsByTagName("input").item(i);
if(dd.type == "checkbox")
{

if(dd.checked)
{
flag=1; }

}
}

}
catch(e)
{
//alert(e);
}
}
# 5
倒,就不能专门针对checkboxlist来写个通用的吗
bobowu-bobo at 2007-11-1 > top of Msdn China Tech,.NET技术,ASP.NET...
# 6
自己搞定,只好做到usercontrol里了
if (!Page.IsClientScriptBlockRegistered("CheckBoxInput_Check"))
{
string script = @"
<script language='javascript'><!--
function CheckBoxInput_Check(checkboxName, itemCount)
{
var hasChecked = false;
for (i = 0 ; i < itemCount ; i ++)
{
if (document.all[checkboxName + ':' + i].checked == true)
{
hasChecked = true;
break;
}
}

return hasChecked;
}
//--></script>
";
Page.RegisterClientScriptBlock("CheckBoxInput_Check" , script);
}

this.CusCheckBox.ClientValidationFunction = "CheckBoxInput_" + this.ClientID;

if (!Page.IsClientScriptBlockRegistered("CheckBoxInput_Check_" + this.ClientID))
{
string customerScript = @"
<script language='javascript'><!--
function CheckBoxInput_" + this.ClientID + @"(source, arguments)
{
var checkboxName = '" + this.CheckBox.UniqueID + @"';
var itemCount = " + this.CheckBox.Items.Count + @";

arguments.IsValid = CheckBoxInput_Check(checkboxName , itemCount);
}
//--></script>
";
Page.RegisterClientScriptBlock("CheckBoxInput_Check_" + this.ClientID , customerScript);
}
}

/// <summary>
/// 服务器验证。
/// </summary>
/// <param name="source"></param>
/// <param name="args"></param>
private void CusCheckBox_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
for (int i = 0 ; i < this.CheckBox.Items.Count ; i ++)
{
if (this.CheckBox.Items[i].Selected)
{
args.IsValid = true;
return;
}
}

args.IsValid = false;
}
bobowu-bobo at 2007-11-1 > top of Msdn China Tech,.NET技术,ASP.NET...
# 7
本来是想看有没有人把这个做成验证器控件的,结果最好还是要自己做成用户控件里用,呜………………
bobowu-bobo at 2007-11-1 > top of Msdn China Tech,.NET技术,ASP.NET...