As others already pointed out, a message box will be clientside Javascript. So the problem then is how to force a clientside JS message box from the server side. A simple solution is to include this in the HTML:
<script>
var data = '<%= JsData %>';
alert(data);
</script>
and to fill this data
from the server side code-behind:
public partial class PageName : Page
{
protected string JsData = "your message";
Note that the string value should be a Javascript string, i.e. be a one-liner, but it may contain escaped newlines as \n
.
Now you can use all your Javascript or JQuery skills and tricks to do whatever you want with that message text on the clientside, such as display a simple alert()
, as shown in the above code sample, or sophisticated message box or message banner.
(Note that popups are sometimes frowned upon and blocked)
Note also that, due to the HTTP protocol, the message can only be shown in response to an HTTP request that the user sends to the server. Unlike WinForm apps, the web server cannot push a message to the client whenever it sees fit.
If you want to show the message only once, and not after the user refreshes the page with F5, you could set and read a cookie with javascript code. In any case, the nice point with this method is that it is an easy way to get data from the server to the javascript on the client, and that you can use all javascript features to accomplish anything you like.