If you're utilizing AJAX, one method I have discovered to alert a user upon returning from an asynchronous post back event is by adding an "end request" handler to the PageRequestManager.
This allows you to specify a JavaScript function to run when coming back from an AJAX asynchronous post back event.
To implement this, use the following code:
function load()
{
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
Where "EndRequestHandler" should be the name of your desired JavaScript function to call.
Invoke the above function in the Onload event of the <body> tag:
<body onload="load()">
function EndRequestHandler()
{
alert("Your record has been successfully saved");
}
If you want to display a different message based on server-side logic (code-behind), you can utilize a hidden field:
<input id="hdnValue" type="hidden" runat="server" value="" />
Set the value of this hidden field in server-side code during an asynchronous post back:
Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreateSample.Click
If condition Then
hdnValue.value = "do this"
Else
hdnValue.value = "do that"
End If
End Sub
You can then check the value of the hidden field in your client-side EndRequestHandler function and display a different alert based on its value:
function EndRequestHandler()
{
if (document.getElementById('<%= hdnValue.ClientID %>').value == "do this")
{
alert("Your record has been successfully saved");
}
else
{
alert("There is an error");
}
}