2011-06-06 125 views
0

嗨 下面是我使用的登录页面的代码,但它不进入按钮click.and当我试图把新的按钮,其按钮点击事件打开在aspx页面。 我不明白问题在哪里。问题从登录页面重定向页面

protected void btnSubmit_Click(object sender, EventArgs e) 
{ 
    string password = ""; 
    string query = "select AdminPwd from tbladminlogin where AdminId='" + txtUserName.Text + "'"; 
    MySqlConnection objMyCon = new MySqlConnection(strProvider); 
    objMyCon.Open(); 
    MySqlCommand cmd = new MySqlCommand(query, objMyCon); 
    MySqlDataReader r = cmd.ExecuteReader(); 
    while (r.Read()) 
    { 
     password = r[0].ToString(); 
    } 
    if (password == "") 
    { 
     Session["Login"] = false; 
     lblMessage.Visible = true; 
     lblMessage.Text = "Invalid Username"; 
     txtUserName.Text = ""; 
     txtPwd.Text = ""; 
    } 
     // 
    else 
    { 
     if (txtPwd.Text == password) 
     { 
      Session["Login"] = true; 
      Session["UserName"] = txtUserName.Text; 

      Response.Redirect("concertDetail.aspx"); 
     } 
     else if (txtPwd.Text != password) 
     { 
      Session["Login"] = false; 
      lblMessage.Visible = true; 
      lblMessage.Text = "Invalid Password"; 
      txtPwd.Text = ""; 
     } 
    } 
    objMyCon.Close(); 
} 

// aspx页

<div id="login"> 
    <%--<div class="response-msg success ui-corner-all"> 
         <span>Success message</span> 
         Lorem ipsum dolor sit amet, consectetuer adipiscing elit 
        </div>--%> 
    <asp:Label ID="lblMessage" runat="server" Text="Label" Font-Size="Medium" ForeColor="Red"></asp:Label> 
    <form id="Form1" runat="server"> 
    <ul> 
     <li> 
      <label for="email" class="desc"> 
       Username: 
      </label> 
      <div> 
       <%--<input type="text" tabindex="1" maxlength="255" value="" class="field text full" name="email" id="email" />--%> 
       <asp:TextBox ID="txtUserName" runat="server" MaxLength="255" Width="470px"></asp:TextBox> 
      </div> 
     </li> 
     <li> 
      <label for="password" class="desc"> 
       Password: 
      </label> 
      <div> 
       <%--<input type="text" tabindex="1" maxlength="255" value="" class="field text full" name="password" id="password" />--%> 
       <asp:TextBox ID="txtPwd" runat="server" MaxLength="255" Width="470px"></asp:TextBox> 
      </div> 
     </li> 
     <li class="buttons"> 
      <div style="position: relative; top: -4px; left: 408px; width: 67px; height: 32px;"> 
       <div style="position: relative;"> 
       </div> 
       <%--<button class="ui-state-default ui-corner-all float-right ui-button" onclick="btnSubmit_Click" type="submit">Login</button>--%> 
       <asp:Button ID="btnSubmit" runat="server" Text="Login" OnClick="btnSubmit_Click" /> 
      </div> 
     </li> 
    </ul> 
</form> 

+0

尝试格式化您的代码。也尽量只发布最小的可以理解的部分供我们看看。 – rerun 2011-06-06 07:54:31

+0

你不是使用asp.net登录控件来做这个吗? – 2011-06-06 07:55:17

+1

也把asp:标签放在表单标签中,否则页面不会编译 – naveen 2011-06-06 07:56:38

回答

0

下面搜索onClick事件在JavaScript和不代码隐藏的功能 “btnSubmit_Click” 时,由于按钮是一个html控制:

<button class="ui-state-default ui-corner-all float-right ui-button" onclick="btnSubmit_Click" type="submit">Login</button> 

至于asp:Button,它应该工作。它似乎没有任何问题。请检查ASP.NET开发服务器是否已经运行。接下来清除缓存并检查浏览器中是否启用了调试。

就双击问题而言,应该禁用它。对我而言,最好的解决方案就是像这样在客户端处理它:

<script> 
    var reqSubmitted = false; 
    function submitRequest() { 
     if (!reqSubmitted) { 
      reqSubmitted = true; 
      return reqSubmitted; 
     } 
     reqSubmitted = false; 
     return reqSubmitted; 
    } 
</script> 

......................的

<form id="Form1" runat="server"> 

<form id="Form1" runat="server" defaultbutton="btnSubmit"> 

代替:..................

<form id="Form1" runat="server" onsubmit="return submitRequest()"> 
+0

调试已启用,并且该行已被注释掉。我已采取asp按钮。 – user755230 2011-06-06 08:52:33

+0

@ user755230,我知道html按钮被注释掉了。我只是在讲它最初不起作用的原因。此外,当“我试图放置新按钮时,它的按钮单击事件在aspx页面中打开”是什么意思?你的意思是代码隐藏中的按钮点击事件是否正在执行?在调试时,你在哪一行得到异常?另外“strProvider”在哪里定义? – 2011-06-06 09:29:21

+0

所有.cs文件。但是当我双击按钮时,它应该打开函数来编写.cs文件中的代码,但它在.aspx文件中打开

0

把这个之前说过请使用parametrized query来避免sql注入和其他许多问题。