Creating a Pop-Up Using ASP.NET VB

I have searched for a way to create a simple popup on my project. Something that is scalable and reusable. I found the answer and I do not know why I never thought of this. It consists of a little five line function. It can probably be done in C# as well.  I just haven’t taken the time to convert it over.  Well here it is.  All you have to do is pass in the page, the message, and a key.

 

CreateMessageAlert(page, message, “keyname”)

 

Message has to be type of string:

Dim message As String

 

Below is the code to implement the above call:

 

Public Shared Sub CreateMessageAlert(ByRef aspxPage As System.Web.UI.Page, _

                           ByVal strMessage As String, ByVal strKey As String)

        Dim strScript As String = “<script language=JavaScript>alert(‘” _

                                            & strMessage & “‘)</script>

        If (Not aspxPage.IsStartupScriptRegistered(strKey)) Then

            aspxPage.RegisterStartupScript(strKey, strScript)

        End If

    End Sub

 

That is it. Not too bad. Pretty easy stuff. Hope this helped.  Have fun coding and as always, if there are any questions or suggestions, they are welcome.  Thank you.