ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
You can use this method, but make sure that Page.Redirect() not used. If you want to redirect to another page, you can try the following:
page.aspx:
<asp:Button AccessKey="S" ID="submitBtn" runat="server" OnClick="Submit" Text="Submit" Width="90px" ValidationGroup="vg" CausesValidation="true" OnClientClick = "Confirm()" />
JavaScript Code:
function Confirm() { if (Page_ClientValidate()) { var confirm_value = document.createElement("INPUT"); confirm_value.type = "hidden"; confirm_value.name = "confirm_value"; if (confirm("Data has been Added. Do you wish to Continue ?")) { confirm_value.value = "Yes"; } else { confirm_value.value = "No"; } document.forms[0].appendChild(confirm_value); } }
and this is your code behind the snippet:
protected void Submit(object sender, EventArgs e) { string confirmValue = Request.Form["confirm_value"]; if (confirmValue == "Yes") { Response.Redirect("~/AddData.aspx"); } else { Response.Redirect("~/ViewData.aspx"); } }
This will work.
source share