菜问题
“RequiredFieldValidator1”的 ControlToValidate 属性不能为空。
上面是错误提示。帮我看看那里写的不对,见笑了。
aspx:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head runat= "server ">
<title> 登陆页 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<table>
<tr>
<td colspan= "2 " style= "height: 180px ">
</td>
</tr>
<tr>
<td style= "width: 350px ">
</td>
<td style= "width: 342px ">
<div style= "background-position-x: center; background-attachment: scroll; background-repeat: repeat-x ">
<asp:Login ID= "Login1 " runat= "server " BackColor= "#EFF3FB " BorderColor= "#B5C7DE " BorderPadding= "4 "
BorderStyle= "Solid " BorderWidth= "1px " Font-Names= "Verdana " Font-Size= "10pt " ForeColor= "#333333 "
CreateUserText= "注册 " CreateUserUrl= "~/UserReg.aspx " DestinationPageUrl= "~/Main_0.aspx "
Height= "173px " HelpPageText= "变更密码 " HelpPageUrl= "~/ChangPassword.aspx " PasswordRecoveryText= "找回密码 "
PasswordRecoveryUrl= "~/PasswordRecovery.aspx " Width= "279px " OnLoggedIn= "Login1_LoggedIn ">
<TitleTextStyle BackColor= "#507CD1 " Font-Bold= "True " Font-Size= "10pt " ForeColor= "White " />
<InstructionTextStyle Font-Italic= "True " ForeColor= "Black " />
<TextBoxStyle Font-Size= "10pt " />
<LoginButtonStyle BackColor= "White " BorderColor= "#507CD1 " BorderStyle= "Solid " BorderWidth= "1px "
Font-Names= "Verdana " Font-Size= "10pt " ForeColor= "#284E98 " />
</asp:Login>
<asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " Font-Size= "10pt "
InitialValue= "【--请选择科室--】 " Style= "left: 61px; position: relative; top: 0px " Width= "96px "> 请选择科室 </asp:RequiredFieldValidator>
<asp:LoginName ID= "LoginName1 " runat= "server " Font-Size= "10pt " ForeColor= "Maroon "
FormatString= "{0}:你好,欢迎光临本站! " Height= "16px " Style= "position: relative; left: 4px; top: 3px; " Width= "247px " />
<br />
<asp:DropDownList ID= "DropDownList1 " runat= "server " AutoPostBack= "True " Font-Size= "10pt "
Style= "left: 2px; position: relative; top: -38px " Width= "55px ">
<asp:ListItem> 一科 </asp:ListItem>
<asp:ListItem> 二科 </asp:ListItem>
<asp:ListItem> 三科 </asp:ListItem>
<asp:ListItem> 四科 </asp:ListItem>
</asp:DropDownList> </div>
</td>
</tr>
</table>
</form>
</body>
</html>
cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
DropDownList DropDownList1 = new DropDownList();
if (DropDownList1.Text == "一科 ")
{
Response.Redirect( "~/ks1/Main_1.aspx ");
}
else if (DropDownList1.Text == "二科 ")
{
Response.Redirect( "~/ks2 / Main_2.aspx ");
}
else if (DropDownList1.Text == "三科 ")
{
Response.Redirect( "~/ks3 / Main_3.aspx ");
}
else if (DropDownList1.Text == "四科 ")
{
Response.Redirect( "~/ks4 / Main_4.aspx ");
}
}
}
[解决办法]
ControlToValidate= "DropDownList1 "
把这个加进去
------------------------
<asp:RequiredFieldValidator ID= "RequiredFieldValidator1 " runat= "server " Font-Size= "10pt " InitialValue= "【--请选择科室--】 " Style= "left: 61px; position: relative; top: 0px " Width= "96px "> 请选择科室 </asp:RequiredFieldValidator>