有现成的RequiredFidldValidator,给你写个示例

<%@   Page   Language= "c# "   Debug= "true "%>
<script   language= "C# "   runat= "server ">
void   Page_Load(Object   Source,   EventArgs   E)  
{
}

void   submit(object   src,EventArgs   e){
Response.Write( "提交成功! ");
}
</script>
<html>
<head>
<title>   Webdiyer   asp.net示例   </title>
</head>
<body>

<form   runat= "server "   method= " ">
<asp:radiobuttonlist   runat= "server "   id= "rbl ">
<asp:ListItem   value= "0 "> zero </asp:ListItem>
<asp:ListItem   value= "1 "> one </asp:ListItem>
<asp:ListItem   value= "2 "> two </asp:ListItem>
<asp:ListItem   value= "3 "> three </asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator   controlToValidate= "rbl "     errorMessage= "RadioButtonList不能不选 "   runat= "server "/>
<br>
<asp:DropDownList   runat= "server "   id= "ddl ">
<asp:ListItem   value= "0 "> 请选择 </asp:ListItem>
<asp:ListItem   value= "1 "> one </asp:ListItem>
<asp:ListItem   value= "2 "> two </asp:ListItem>
<asp:ListItem   value= "3 "> three </asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator   controlToValidate= "ddl "   initialValue= "0 "   errorMessage= "DropDownList不能选择第一项 "   runat= "server "/>
<p>
<asp:Button   runat= "server "   id= "btn "   Text= "提交 "   onclick= "submit "/>
</form>
</body>
</html>

posted on 2010-09-27 18:57  王培  阅读(173)  评论(0编辑  收藏  举报

导航