嗨 下面是我使用的登錄頁面的代碼,但它不進入按鈕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>
嘗試格式化您的代碼。也儘量只發布最小的可以理解的部分供我們看看。 – rerun 2011-06-06 07:54:31
你不是使用asp.net登錄控件來做這個嗎? – 2011-06-06 07:55:17
也把asp:標籤放在表單標籤中,否則頁面不會編譯 – naveen 2011-06-06 07:56:38