我有一个aspx页面...登录按钮我有一个点击事件。但是当我点击按钮时页面被重新加载。可能是错误。我无法理解。并且登录按钮位于表单标签中。 aspx页面上的登录代码: - >
.cs文件上的代码
protected void Login_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
string q = "SELECT * FROM Instructor WHERE EmailId='" + TextBox10.Text + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbstring"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand(q, con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
if (dt.Rows.Count == 1)
{
if (dt.Rows[0]["Password"].ToString() == TextBox2.Text)
{
Session["instructor"] = TextBox10.Text;
Response.Redirect("InstructorHome.aspx");
}
else
{ Label1. Visible = true;
Label1.Text = "Password Incorrect";
}
}
else
{
Label2. Visible = true;
Label2.Text = "Username does not Exists";
TextBox10.Text = "";
}
con.Close();
}
<h2>Log In</h2>
<form id="LogIn" action="#">
<div>
<div class="wrapper"> <asp:Label ID="Label10" runat="server" Text="Enter Your EmaiID" Font-Size="Medium" ForeColor="Black" Font-Names="Algerian" ></asp:Label>
<div class="bg">
<asp:TextBox ID="TextBox10" runat="server" Font-Names="Comic Sans MS" Font-Size="Medium" ></asp:TextBox>
<asp:CustomValidator ID="CustomValidator14" runat="server" ErrorMessage="Enter Valid Email ID" ControlToValidate="TextBox10" ValidateEmptyText="True" ClientValidationFunction="EmailValidator" ValidationGroup="fp" Font-Size="Medium" ForeColor="Black" Font-Names="Algerian"></asp:CustomValidator><br />
<asp:CustomValidator ID="CustomValidator15" runat="server" ErrorMessage="Cannot Be Empty" ControlToValidate="TextBox10" ValidateEmptyText="True" ClientValidationFunction="RequiredValidate" ValidationGroup="fp" Font-Size="Medium" ForeColor="Black" Font-Names="Algerian"></asp:CustomValidator>
</div>
</div>
<div class="wrapper"><asp:Label ID="Label9" runat="server" Text="Password" Font-Size="Medium" ForeColor="Black" Font-Names="Algerian" ></asp:Label>
<div class="bg">
<asp:TextBox ID="TextBox2" TextMode="Password" runat="server" Font-Names="Comic Sans MS" Font-Size="Medium"></asp:TextBox>  
<asp:Label ID="Label13" runat="server" Text="" Font-Size="Medium" ForeColor="Black" Font-Names="Algerian"></asp:Label> </div>
<asp:CustomValidator ID="CustomValidator13" runat="server" ErrorMessage="Cannot Be Empty" ControlToValidate="TextBox2" ValidateEmptyText="True" ClientValidationFunction="RequiredValidate" ValidationGroup="loginValidate" Font-Size="Medium" ForeColor="Black" Font-Names="Algerian"></asp:CustomValidator><br />
</div>
<asp:Button ID="Button2" class="button" runat="server" Text="Login" onclick="Login_Click" validationgroup= "loginValidate" ></asp:Button>
<asp:Button ID="Button3" class="button" runat="server" Text="Forgot Password" onclick="Forgot_click" ValidationGroup="fp"></asp:Button>
</div>
<asp:Label ID="Label1" runat="server" Text="Label" Visible="false"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label" Visible="false"></asp:Label>
</form>
答案 0 :(得分:1)
发布你的page_load代码,我怀疑你可能会在这里做点什么,如果是这样的话就把它包装好了。
if (!page.ispostback) {
//your page load code here...
}