The below vb.net 3.5 code meets these criteria:
Module PageExtensions
<extension()> _
Public Sub MsgBox(ByVal aPage As Page, ByVal aMessage As String)
Dim timeStr As String = "msgbox" & Date.Now().Ticks.ToString
' Set a cookie after showing alert so as will not re-show if back button or refresh is used.
Dim alertScript As String = "if (document.cookie.indexOf('" & timeStr & "') == -1) {"
alertScript &= "alert(""" & aMessage & """);"
alertScript &= "document.cookie = '" & timeStr & "=deleted';}"
System.Web.UI.ScriptManager.RegisterStartupScript(aPage, GetType(String), aMessage, alertScript, True)
End Sub
End Module
To use within a page, you can now simply type:
MsgBox("Hello World"), just like in a Windows App.
A temporary cookie is set for each msgbox invoked so that the msgbox will only be shown once. The method is an extension method of the Page class, so needs to be contained within a Module, or used without the attribute.
A temporary cookie is set for each msgbox invoked so that the msgbox will only be shown once. The method is an extension method of the Page class, so needs to be contained within a Module, or used without the
Note also you will need a reference to System.Web.Extensions in your project.