我的註冊按鈕事件是當用戶註冊成功並將他重定向到登錄頁面時,如何顯示消息框?
protected void signup_Click(object sender, EventArgs e)
{
string con = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
SqlConnection conn = new SqlConnection(con);
conn.Open();
if (selectques.SelectedItem.Text == "Write your own question?")
{
SqlCommand cmd = new SqlCommand("insert into registration values('" + username.Text + "','" + passwrd.Text + "','" + emailadd.Text + "','" + alterquestion.Text + "','" + securityanswer.Text + "')", conn);
cmd.ExecuteNonQuery();
Response.Redirect("Login.aspx");
try {
ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Successful Registered');window.location='login.aspx';", true);
}
catch(Exception ex)
{
}
}
else
{
SqlCommand cmd = new SqlCommand("insert into registration values('" + username.Text + "','" + passwrd.Text + "','" + emailadd.Text + "','" + selectques.Text + "','" + securityanswer.Text + "')", conn);
cmd.ExecuteNonQuery();
Response.Redirect("login.aspx");
try
{
ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Successful Registered');window.location='login.aspx';", true);
}
catch (Exception ex)
{
}
}
}
成功註冊我怎麼能顯示出Successful Registered
消息在登錄頁面或在同一頁上後。我想通過彈出窗口或消息框顯示消息。
刪除「Response.Redirect(」Login.aspx「);」並檢查... – Nalaka526
下面的答案提出了一個很好的觀點,你的SQL代碼在這裏是非常危險的。除了明顯的SQL注入問題,您不應該直接在ASP.NET頁面內執行SQL。爲了可維護性,您應該從Web層代碼中分離出您的數據訪問代碼。 – SoWeLie
@ Nalaka526非常感謝你解決了我的問題。我告訴你我在執行我需要的代碼之前將它重定向到另一頁上。謝謝發佈它作爲答案我會接受它。 – avirk