如何使用RequiredFieldValidator控件验证DropDownList?
2009-10-22 17:18
465 查看
<%@ Page Language=
"C#"
%>
<script runat=
"server"
>
void
btnSubmit_Click
(
Object sender, EventArgs e
)
{
if
(
Page.IsValid
)
lblResult.Text = dropFavoriteColor.SelectedValue;
}
</script>
<
html
xmlns=
"http://www.w3.org/1999/xhtml"
>
<head id=
"Head1"
runat=
"server"
>
<title>Show Initial Value</title>
</head>
<
body
>
<
form
id=
"form1"
runat=
"server"
>
<div>
<asp:Label
id=
"lblFavoriteColor"
Text=
"Favorite Color:"
AssociatedControlID=
"dropFavoriteColor"
Runat=
"server"
/>
<br />
<asp:DropDownList
id=
"dropFavoriteColor"
Runat=
"server"
>
<asp:ListItem Text=
"Select Color"
Value=
"none"
/>
<asp:ListItem Text=
"Red"
Value=
"Red"
/>
<asp:ListItem Text=
"Blue"
Value=
"Blue"
/>
<asp:ListItem Text=
"Green"
Value=
"Green"
/>
</asp:DropDownList>
<asp:RequiredFieldValidator
id=
"reqFavoriteColor"
Text=
"(Required)"
InitialValue=
"none"
ControlToValidate=
"dropFavoriteColor"
Runat=
"server"
/>
<br /><br />
<asp:Button
id=
"btnSubmit"
Text=
"Submit"
Runat=
"server"
OnClick=
"btnSubmit_Click"
/>
<hr />
<asp:Label
id=
"lblResult"
Runat=
"server"
/>
</div>
</
form
>
</
body
>
</
html
>
"C#"
%>
<script runat=
"server"
>
void
btnSubmit_Click
(
Object sender, EventArgs e
)
{
if
(
Page.IsValid
)
lblResult.Text = dropFavoriteColor.SelectedValue;
}
</script>
<
html
xmlns=
"http://www.w3.org/1999/xhtml"
>
<head id=
"Head1"
runat=
"server"
>
<title>Show Initial Value</title>
</head>
<
body
>
<
form
id=
"form1"
runat=
"server"
>
<div>
<asp:Label
id=
"lblFavoriteColor"
Text=
"Favorite Color:"
AssociatedControlID=
"dropFavoriteColor"
Runat=
"server"
/>
<br />
<asp:DropDownList
id=
"dropFavoriteColor"
Runat=
"server"
>
<asp:ListItem Text=
"Select Color"
Value=
"none"
/>
<asp:ListItem Text=
"Red"
Value=
"Red"
/>
<asp:ListItem Text=
"Blue"
Value=
"Blue"
/>
<asp:ListItem Text=
"Green"
Value=
"Green"
/>
</asp:DropDownList>
<asp:RequiredFieldValidator
id=
"reqFavoriteColor"
Text=
"(Required)"
InitialValue=
"none"
ControlToValidate=
"dropFavoriteColor"
Runat=
"server"
/>
<br /><br />
<asp:Button
id=
"btnSubmit"
Text=
"Submit"
Runat=
"server"
OnClick=
"btnSubmit_Click"
/>
<hr />
<asp:Label
id=
"lblResult"
Runat=
"server"
/>
</div>
</
form
>
</
body
>
</
html
>
相关文章推荐
- c# web 如何使用RequiredFieldValidator控件验证CheckBoxList
- 如何使用RequiredFieldValidator控件验证CheckBoxList
- 如何使用RequiredFieldValidator控件验证CheckBoxList?
- c# web 如何使用RequiredFieldValidator控件验证CheckBoxList
- 如何让验证控件在页面打开时就显示红色的*(RequiredFieldValidator )
- 验证控件的使用二(RequiredFieldValidator )
- 表单验证ASP.NET RequiredFieldValidator 控件使用方法及使用实例
- RequiredFieldValidator控件验证使用
- ASP.NET中Textbox后的必填验证控件RequiredFieldValidator的使用方法。
- DropDownList--必选验证,,RequiredFieldValidator控件,InitialValue属性
- 【翻译】如何对RadioButtonList, DropDownList, ListBox等ListItem控件使用RequiredFieldValidator
- ASP.NET中 RequiredFieldValidator(非空验证)的使用
- 输入的有效性验证RequiredFieldValidator控件(非空验证)
- RequiredFieldValidator验证控件的应用
- (转)ASP.NET一个页面多个Button按钮事件避免数据验证控件RequiredFieldValidator冲突方法
- FCKEditor使用RequiredFieldValidator验证
- RequiredFieldValidator----验证控件不起作用
- ASP.NET验证控件之RequiredFieldValidator
- ASP.NET一个页面多个Button按钮事件避免数据验证控件RequiredFieldValidator冲突方法
- asp.net控件RequiredFieldValidator验证FCKeditor提交两次才能成功的解决方法