2011-06-06 123 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注入和其他許多問題。