One way to popup a message box from an ASP.NET application.

By Ken Fitzpatrick

Many developers don't understand the that the Messagebox() function cannot be called from code-behind in an ASP.Net application, yet they will still reference the System.Windows.Forms.dll just to use it and find out it won't work. The only way to popup a message in an ASP.Net app is to trigger the client-side code to do it with an alert() in Javascript, a msgbox() in vbscript, or in the form of a a confirm() in javascript. There are many ways to trigger the client to do it, here is one way.

'This method will take a message as a string and render the Javascript on the client to pop up an alert
'It can be called multiple times for multiple pop-ups.
Private Sub PopUpClientMessage(ByVal myMessage As String)
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopupMessage", "alert('" & myMessage & "';", True)
End Sub

One way to popup a message box from an ASP.NET application.  (663 Views)
Create New Account