tags:

views:

91

answers:

2

Work on ASP.net C# vs 05.

To Preventing Duplicate Record Insertion on Page Refresh. Under the button event i wrote below code

Response.Redirect(Request.Url.ToString(), false);

i also used a javascript alert under this event ,after use the above code alert message is not showing,display message boxes from server-side code?

string message = "Data saved successfully.";
        string s = "<script type=\"text/javascript\">alert('" + message + "');</script>";
        ClientScript.RegisterStartupScript(GetType(), "Alert", s);
A: 
try{ 
    Response.Redirect(Request.Url.ToString(), false);
}catch(e){
    alert(e.message);
}
Anatoliy
A: 

Alert dialog is probably showing up, but you have no chance to see it because page is redirected.

You could add something to query string when redirecting. Look for it on pageload and inject alert javascript on pageload instead of doing it at button click event.

End of save event:

Response.Redirect("/page_you_want_to_redirect_to.aspx" + "?save=success");

On the redirected page:

public void Page_Load(object sender, System.EventArgs e)
{
    //...

    if (!Page.IsPostBack && String.Equals(Request.QueryString["save"], "success"))
    {
        string s = "<script type=\"text/javascript\">alert('Data saved successfully.');</script>";
        ClientScript.RegisterStartupScript(GetType(), "SaveAlert", s);
    }

    //...
}

More elegant solution would be to make async call and show modal dialog. Refreshing the page won't cause postback this way. You can easily accomplish this by dropping in an UpdatePanel and use some jQuery for modal dialog.

Brian Kim