我使用多个视图控件和2个自定义验证,问题是当我单击下一个按钮以下一步查看视图1中未显示的错误消息时, 我试图将视图分离到单独的页面中,并且代码成功运行,但是由于DB的其他问题,我不需要完全分开需要的页面。 我该怎么办?
这是asp.net代码的一部分 {
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<div runat="server" id="Div2" >
<div class="divStyle">
<table class="auto-style16">
<tr>
<td class="auto-style17"> </td>
<td class="auto-style1">الايميل<asp:RequiredFieldValidator ID="RequiredFieldValidator42" runat="server" ErrorMessage="RequiredField" ForeColor="red" ControlToValidate="TextBox9">*</asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator3" runat="server" ErrorMessage="CustomValidator" ControlToValidate="TextBox9" OnServerValidate="CustomValidator3_ServerValidate">*</asp:CustomValidator>
</td>
<asp:Button ID="Button1" runat="server"
Text="التالي" style="color:#8fbbbc; font-size:105%; font-weight:bold;" BackColor="white" BorderColor="White" BorderStyle="inset" Height="47px" Width="81px"
CommandArgument="View2"
CommandName="SwitchViewByID" />
}
这是自定义验证代码 {
protected void CustomValidator3_ServerValidate(object source, ServerValidateEventArgs args)
{
const string ConnectionString = "Data Source=.\\sqlexpress;Initial Catalog=seq;Integrated Security=True";
SqlConnection con = new SqlConnection(ConnectionString);
string sql2;
con.Open();
sql2 = "select Email from applicant where Email = @em";
SqlCommand com2 = new SqlCommand(sql2, con);
com2.Parameters.AddWithValue("@em", TextBox9.Text);
SqlDataReader rd = com2.ExecuteReader();
if (rd.HasRows)
{
args.IsValid = false;
Label3.Text = "الايميل مكرر";
}
else { args.IsValid = true; }
rd.Close();
con.Close();
}