一个刚学APS.net请教验证控件的问题,谢谢大家
1.一个下拉列表
<asp:DropDownList runat= "server " ID= "dropweek1 ">
<asp:ListItem Selected = "true " Value= "0 " > ---请选择--- </asp:ListItem>
<asp:ListItem Value= "1 " > 星期一 </asp:ListItem>
<asp:ListItem Value= "2 " > 星期二 </asp:ListItem>
<asp:ListItem Value= "3 " > 星期三 </asp:ListItem>
<asp:ListItem Value= "4 " > 星期四 </asp:ListItem>
<asp:ListItem Value= "5 " > 星期五 </asp:ListItem>
<asp:ListItem Value= "6 " > 星期六 </asp:ListItem>
<asp:ListItem Value= "7 " > 星期天 </asp:ListItem>
</asp:DropDownList>
请问用那种验证控件或方法可以让一定得选择星期几!
2.一个textbox,怎么验证里面必填且是日期!
这个知道用CompareValidator可以验证正确日期格式,但怎么验证必填呢,用一个验证控件最好
谢谢大家能帮帮忙!!!
[解决办法]
private void Button1_Click(object sender, System.EventArgs e)
{
if(this.DropDownList1.Items[0].Selected)
{
this.Response.Write( "星期 ");
}
else
{
//入你想要行的代;
}
}
加一按控件;后代;住用代要把里面的繁成,你可以用word工具。
你的第二。。你可以用自定控件。。然你也可以正则表达式;
[解决办法]
用CustomValidator 调用
然后在前台用JavaScript验证.
[解决办法]
不用那么得杂一个属性就可搞定:InitialValue
<asp:DropDownList runat= "server " ID= "dropweek1 ">
<asp:ListItem Selected = "true " Value= "0 " > ---请选择--- </asp:ListItem>
<asp:ListItem Value= "1 " > 星期一 </asp:ListItem>
<asp:ListItem Value= "2 " > 星期二 </asp:ListItem>
<asp:ListItem Value= "3 " > 星期三 </asp:ListItem>
<asp:ListItem Value= "4 " > 星期四 </asp:ListItem>
<asp:ListItem Value= "5 " > 星期五 </asp:ListItem>
<asp:ListItem Value= "6 " > 星期六 </asp:ListItem>
<asp:ListItem Value= "7 " > 星期天 </asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator InitialValue= "0 " ControlToValidate= "dropweek1 " runat= "server "> 请选择 </asp:RequiredFieldValidator>
[解决办法]
这在用户提交时,会调用前台你自己定义的一个JavaScript function
在CustomValidator 里有一个ClientValidationFunction= "ClientValidate "
然后在前台写
function ClientValidate(source, arguments)
{
if (选择的不是第一个)
arguments.IsValid=true;
else
arguments.IsValid=false;
}
[解决办法]
1、请问用那种验证控件或方法可以让一定得选择星期几!
这个你直接ListItem 只留1个不就好啦,把不要选的remove掉不是更好吗,或者在页面加载的时候系统就帮他选好星期几,然后就设置控件为disabled
2、一个textbox,怎么验证里面必填且是日期!
只能用2个验证控件,或者你自己重写1个CompareValidator,为它加上验证必填的功能
[解决办法]
1、if (dropweek1.selectedvalue == "0 ")
{
//提示请选择日期
}
2、有个控件可以要求其非空:RequiredFieldValidator
---------------------------------------------
EMail:bdbox@163.com 请给我一个与您交流的机会!