[英]How can I show messagebox when user register successfully and redirect him to Login page?
My signUp button event is 我的注册按钮事件是
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)
{
}
}
}
After registering successfully how can I show a message of Successful Registered
on login page or on the same page. 成功注册后,如何在登录页面或同一页面上显示Successful Registered
的消息。 I want to show the message through Popup window or messagebox. 我想通过弹出窗口或消息框显示消息。
A little UI design tip - people HATE popups. UI设计小技巧-人们讨厌弹出式窗口。 Your proposed idea would, of course, need JavaScript - some people have that disabled. 当然,您提出的想法将需要JavaScript-有些人将其禁用。 Not an accessible solution. 不可访问的解决方案。 The simplest way would be to pass a parameter via GET (you could also use sessions) to login.aspx
telling it to echo an additional message at or near the top of the page saying the registration was successful, perhaps with CSS styling to make it look like a window. 最简单的方法是通过GET传递参数(您也可以使用会话)来登录login.aspx
告诉它在页面顶部或附近回显一条附加消息,表明注册已成功,也许使用了CSS样式使其成功看起来像一个窗户。
But please, no alert
s and no popups. 但是请没有alert
,也没有弹出窗口。 It's very poor design. 这是非常糟糕的设计。
I'm pretty sure you should read up on SQL Injection too because what you're doing here is very dangerous. 我很确定您也应该阅读SQL Injection,因为您在这里所做的工作非常危险。
SqlCommand cmd = new SqlCommand(
"insert into registration values('" +
username.Text + "','" + passwrd.Text + "','" +
emailadd.Text + "','" + alterquestion.Text + "','" +
securityanswer.Text + "')", conn);
Remove both Response.Redirect("Login.aspx");
删除两个Response.Redirect("Login.aspx");
and check. 并检查。
It looks like you're posting a form when clicking the signup button, which means you'll need to render a bit of JavaScript to show the popup then to redirect, rather than doing the redirect server side. 看起来您在单击“注册”按钮时正在发布表单,这意味着您需要渲染一些JavaScript以显示弹出窗口然后进行重定向,而不是进行重定向服务器端。
Your other option would be to call your register action through AJAX, and if the signup is successful, again show the alert client side and also redirect client side. 您的另一个选择是通过AJAX调用您的注册操作,如果注册成功,则再次显示警报客户端并重定向客户端。
移动Response.Redirect("Login.aspx");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.