我有一個ASPX網頁,它有四個字段,電子郵件,確認電子郵件,密碼,確認密碼和顯示名稱。我已將代碼放在頁面後面的代碼中,以便按下注冊按鈕時,它應提交信息並向數據庫添加新用戶。但是,當我點擊按鈕時,它只刷新頁面。我試圖搞亂後面的代碼,這樣當按鈕被點擊時,它只是重定向到主頁,沒有if語句,但它仍然刷新頁面。 下面是相關的代碼背後:註冊按鈕刷新頁面,不添加用戶
namespace PiccyPic
{
public partial class Login : System.Web.UI.Page
{
protected void butRegisterDefine(object sender, EventArgs e)
{
butRegister.Click += butRegister_Click;
}
void butRegister_Click(object sender, EventArgs e)
{
using (DataLayer.Repository db = new DataLayer.Repository())
{
BO.User user = db.UserGet(txtEmail.Text);
if (user != null)
{
//If the same email exists
pnlError.Visible = true;
lblError.Text = "Error: The email you have entered is already assigned to an account.";
}
else if (user.Username != null)
{
//If the same username exists
pnlError.Visible = true;
lblError.Text = "Error: The username you have entered is already assigned to an account.";
}
else if (txtEmail.Text != txtEmailConfirm.Text)
{
//If the emails don't match
pnlError.Visible = true;
lblError.Text = "Error: The emails you have entered do not match";
}
else if (txtPassword.Text != txtPasswordConfirm.Text)
{
//If the passwords don't match
pnlError.Visible = true;
lblError.Text = "Error: The passwords you have entered do not match";
}
else
{
// Add user
var newUser = new BO.User(txtEmail.Text, txtPassword.Text, txtUsername.Text);
db.UserAdd(newUser);
db.Save();
Response.Redirect("Default.aspx");
}
}
}
}
是否有任何JavaScript。尋找JavaScript錯誤。 – 2014-10-10 11:40:03
沒有javascript錯誤 – Frayt 2014-10-10 11:59:17
這不是傳統的ASP。請重新登錄。 – Paul 2014-10-13 07:37:26