//验证提交控件内容是否为空
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#tbList
{
border-top: 1px solid #0088F7;
border-left: 1px solid #0088F7;
width: 930px;
}
#tbList td, th
{
border-bottom: 1px solid #0088F7;
border-right: 1px solid #0088F7;
font-size: 16px;
}
.textbox
{
border-left: solid 0 #ffffff;
border-bottom: solid 1px #716E6F;
border-right: solid 0 #ffffff;
border-top: solid 0 #ffffff;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<br />
<br />
<table id="tbList">
<tr>
<td align="right">
姓名
</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
<td align="right">
年龄
</td>
<td>
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
<asp:Label ID="lbAge" runat="server" Text="年龄不能为空" ForeColor="Red" Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td align="right">
民族
</td>
<td>
<asp:TextBox ID="txtPeople" runat="server"></asp:TextBox>
<asp:Label ID="lbPeople" runat="server" Text="民族不能为空" ForeColor="Red" Visible="false"></asp:Label>
</td>
<td align="right">
省份
</td>
<td>
<asp:DropDownList ID="ddlProvince" runat="server">
<asp:ListItem>辽宁</asp:ListItem>
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>上海</asp:ListItem>
<asp:ListItem>广州</asp:ListItem>
<asp:ListItem>美国</asp:ListItem>
<asp:ListItem>英国</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lbProvince" runat="server" Text="省份选择不正确" ForeColor="Red" Visible="false"></asp:Label>
</td>
</tr>
<tr>
<td colspan="4">
<center>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="提交数据" OnClick="btnSubmit_Click" />
<br />
</center>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
//后台CS代码
//提交按钮的功能
protected void btnSubmit_Click(object sender, EventArgs e)
{
string name = txtName.Text;//姓名
string age = txtAge.Text;//年龄
string people = txtPeople.Text;//民族
string strDDLProvince = ddlProvince.SelectedItem.Text;//得到选中的省份文本
{
lbName.Visible = true;//设置姓名错误提示标签为True
return;
}
else
{
lbName.Visible = false;//否则的话把姓名错误提示标签为False
}
{
lbAge.Visible = true;//设置年龄错误提示标签为True
return;
}
else
{
lbAge.Visible = false;//设置年龄错误提示标签为false
}
if (string.IsNullOrEmpty(people))//如果民族不为空的话
{
lbPeople.Visible = true;//设置年龄错误提示标签为True
return;
}
else
{
lbPeople.Visible = false;//设置年龄错误提示标签为False
}
{
lbProvince.Visible = true;//设置省份错误提示标签为True
return;
}
else
{
lbProvince.Visible = false;//设置省份错误提示标签为False
}
}