简体   繁体   English

用户成功注册并将其重定向到“登录”页面后,如何显示消息框?

[英]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.

相关问题 当用户按下MessageBox中的按钮时,如何播放声音? - How can I play a sound when a user presses a button in a MessageBox? 当用户会话过期时如何重定向到页面? - How can I redirect to a page when the user session expires? 用户已经登录后,如何重定向到未授权页面而不是登录页面? - How do I redirect to a not-authorized page instead of the login page when the user is already logged in? 我在ASP.net中登录时如何根据用户重定向页面? - How to redirect the page according to user when I login in ASP.net? WCF上的类成功登录后如何重定向其他页面 - How to redirect other page after successfully login by a class on WCF 当用户单击标题栏中的十字时,如何显示MessageBox提示 - How do I show a MessageBox prompt when the user has clicked the cross in the title bar 从任务管理器中终止程序时,如何显示MessageBox并建议保存更改? - How can I show MessageBox with suggestion of saving changes when I'm killing program from task manager? 按下按钮并成功重定向到另一个页面后,如何禁用导航栏链接? - How can I disable a navbar link after I push a button and successfully redirect to another page? 如果用户未登录,如何重定向到登录视图? - How can I redirect to the login view in case the user is not logged in? 如何在登录时将使用重定向到特定页面给用户? - How to redirect use to specific page to user on login?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM