简体   繁体   中英

How to show Success Message then refresh the webpage

I am trying to refresh the web page after saving the form data to SQL.

When saving the data the success message is displayed. But a soon as I add this code

Response.Redirect("../Clients/NewClient.aspx");

The page then refreshes without he success message.

I know I am doing something wrong here but not sure what?

Here is my code I am using:

 conn.Open();
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(@"connstring", conn);
        cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text);
        cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
        cmd.Parameters.AddWithValue("@CompanyName", txtCompanyName.Text);
        cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
        cmd.Parameters.AddWithValue("@Email", txtEmailAddress.Text);
        cmd.Parameters.AddWithValue("@ContactNumber", txtContactNumber.Text);
        cmd.Parameters.AddWithValue("@WebAddress", txtWebSite.Text);
        cmd.ExecuteNonQuery();
        Toastr.ShowToast("Client Information Saved Successfully", "Success", Toastr.Type.Success);
        Response.Redirect("../Clients/NewClient.aspx");
    }
    catch (Exception ex)
    {

    }
    finally
    {
        conn.Close();
    }
}

You could have your success message include an okay button and then redirect users once that button is clicked:

//If user clicks okay then they are redirected to new page
//if user clicks cancel then nothing happens
ClientScriptManager CSM = Page.ClientScript;

string strconfirm = "<script>if(window.confirm('Client Information Saved Successfully')){window.location.href='../Clients/NewClient.aspx'}</script>";
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);

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