![](/img/trans.png)
[英]How can I play a sound when a user presses a button in a MessageBox?
[英]How can I show messagebox when user register successfully and redirect him to Login page?
我的注冊按鈕事件是
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
的消息。 我想通過彈出窗口或消息框顯示消息。
UI設計小技巧-人們討厭彈出式窗口。 當然,您提出的想法將需要JavaScript-有些人將其禁用。 不可訪問的解決方案。 最簡單的方法是通過GET傳遞參數(您也可以使用會話)來登錄login.aspx
告訴它在頁面頂部或附近回顯一條附加消息,表明注冊已成功,也許使用了CSS樣式使其成功看起來像一個窗戶。
但是請沒有alert
,也沒有彈出窗口。 這是非常糟糕的設計。
我很確定您也應該閱讀SQL Injection,因為您在這里所做的工作非常危險。
SqlCommand cmd = new SqlCommand(
"insert into registration values('" +
username.Text + "','" + passwrd.Text + "','" +
emailadd.Text + "','" + alterquestion.Text + "','" +
securityanswer.Text + "')", conn);
刪除兩個Response.Redirect("Login.aspx");
並檢查。
看起來您在單擊“注冊”按鈕時正在發布表單,這意味着您需要渲染一些JavaScript以顯示彈出窗口然后進行重定向,而不是進行重定向服務器端。
您的另一個選擇是通過AJAX調用您的注冊操作,如果注冊成功,則再次顯示警報客戶端並重定向客戶端。
移動Response.Redirect("Login.aspx");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.