Well it seems to do what i want. Thanks for your help.
Main Topics
Browse All TopicsI am looking to find some code that will allow me to display a message box when called from an asp.net webform. I would like to be able have the code in a class module where i have all of my other generic functions. Then from whereever i what to display the message I just call the function and pass the text that i want to appear as part of the message.
I have found one example that does what i want but when i call it the current web page is blank while the message box is displayed.
I also found the following code in an article here in the experts exchange but i cant seem to get it to work when i call it from a class module. It would if the function is part of the webform but when i try and call it from a class module it get the following error:
"Object reference not set to an instance of an object"
Here is the code that i am using:
Public Sub Display_Message(ByVal strMsg As String)
Dim strScript As String
strScript = "<script language=JavaScript>"
strScript &= "alert(strMsg);"
strScript &= "</script>"
If (Not Page.IsStartupScriptRegist
Page.RegisterStartupScript
End If
Again, this works if the function is part of the page but i want to be able to call it from a class module.
Does any body have any good examples of displaying a message box or any ideas why the above code does not work?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: pillbug22Posted on 2005-06-23 at 08:15:07ID: 14284936
Here's what I use (I have this in a class called Utilities where I keep different helper functions). The only problem is checking to see if the script is already registered...I can see where it might be a problem registering/running the same messagebox twice, but when I have the If statement enabled, it doesn't run at all...
'" _
gistered(s trKey)) Then ript(strKe y, strScript)
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.IsStartupScriptRe
aspxPage.RegisterStartupSc
'End If
End Sub