Onclick按钮不起作用asp.net

时间:2016-12-08 09:17:22

标签: c# asp.net html5

我有一个包含两个字段的登录表单..电子邮件和密码字段,以及一个登录按钮。 起初,登录按钮后面的代码工作得很完美..然后,我离开了这个网站去处理另一个项目,过了一段时间,我在笔记本电脑上再次使用" Admin"帐户,但实际上我并没有尝试按登录按钮。 但是,现在我在" MY"帐户和登录按钮根本不工作,而它之前,我说! 我通过互联网搜索解决方案,但没有一个帮助!我实现的解决方案之一是创建新的Web表单并再次添加代码,但仍然是相同的!登录按钮不起作用,但它没有显示任何错误消息。

这是我的代码:

protected void Button2_Click1(object sender, EventArgs e)
    {

        string email = Request.Form["Email"];
        string pass = Request.Form["Password"];


        if (email == "" || pass == "")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' Enter your email and password please ')", true);
            return;
        }

        SqlCommand cmd = new SqlCommand("Select CountryName from AdministratorsEnglish where AdminEmail = @adminEmail and AdminPassword = @adminPassword", con);
        cmd.Parameters.AddWithValue("@adminEmail", email);
        cmd.Parameters.AddWithValue("@adminPassword", pass);
        con.Open();
        countryName = Convert.ToString(cmd.ExecuteScalar());



        SqlDataAdapter adapt = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adapt.Fill(ds);
        con.Close();
        int count = ds.Tables[0].Rows.Count;
        //If count is equal to 1, than show frmMain form
        if (count == 1)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' Welcome again ! ')", true);
            Session["CountryName"] = countryName;
            Server.Transfer("MainPageEng.aspx", true);

        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' You have enetered wrong information ')", true);
        }
    }

这就是html:

<form class="login-form" >
    <input type="text" placeholder="email" id="emailtxt" name="Email"/>
    <input type="password" placeholder="password" id="passwordtxt" name="Password"/>
      <%--<asp:Button ID="Button1" runat="server" CssClass="auto-style3" OnClick="Button1_Click1" Text="Login" BackColor="Red" />--%>
    <button id="loginbtn" runat="server" onserverclick="Button2_Click1">login</button>

  </form>

我需要帮助!!!

1 个答案:

答案 0 :(得分:1)

只需使用以下内容替换HTML部件:

<div class="login-form">
        <asp:TextBox ID="emailtxt" runat="server" placeholder="email"></asp:TextBox>
        <asp:TextBox ID="passwordtxt" runat="server" TextMode="Password" placeholder="password"></asp:TextBox>
        <asp:Button ID="loginbtn" runat="server" OnClick="Button2_Click1" Text="login"/>
    </div>