简体   繁体   中英

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. I want to show the message through Popup window or messagebox.

A little UI design tip - people HATE popups. Your proposed idea would, of course, need JavaScript - some people have that disabled. 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.

But please, no alert s and no popups. 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.

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"); 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.

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.

移动Response.Redirect("Login.aspx");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM