Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alert all users?

Status
Not open for further replies.

shangrilla

Programmer
Nov 21, 2001
360
0
0
US
How can I send a message to all users currently using the application?

I can use javascript alert and call it on a form load, but I want something that will occur application wide not just when that particular form is loaded. For example in Global.asax file in
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub

Any Ideas?
 
Well, there might be two answers to this question.

1. If you really want to send a message, in real time, to pop up regardless of what the user is doing, then this is difficult. You might look at storing the IP address of everyone who logs in (it is available as a session variable) and using some way to net send them. Or you might place an ActiveX or .net component in the page, or a client script to continually poll your site and see if a message is available to display, but this is likely to be messy.

2. If all you want is any time a form belonging to your app performs a postback, to check for a message and if one is found, display it on the form, or in an alert box, then this is easier. Have a look at the Application object. My idea is to place a string in there, and every server page load, check this. If it contains something, then write the string out to the page, write an alert script out to the page, or make a control with the message in it visible, etc. Use either a web custom control or just a shared function so that you don't have to place the identical code in each web form.

Is this helpful?

In the Global.asax file, I don't think you can do much. You might be able to get a reference to the response stream from there, but I'm not sure.

Mark

Mark [openup]
 
Custom24:

Your 2nd suggestion will do the job for me. I just need to figure out how to use it.

Where do I write the shared function that checks if a message needs to be displayed or not?

Will this work for a web application because msdn has it(Application Class) listed under the windowsForms namespace.
 


From what I understood from your question I hope the following code helps:

on your class:
Public Class1

Public Sub MyMessage(ByVal strMessage As String)
Dim sJavaScript As String
sJavaScript = &quot;<script language=javascript>&quot;
sJavaScript &= &quot;alert('&quot; & strMessage & &quot;');&quot;
sJavaScript &= &quot;</script>&quot;
Response.Write(sJavaScript)
end sub

end Class

on your webform:

dim sMessage as string 'set this to the error message
dim myClass as new Class1
myClass.MyMessage(sMessage)



Hope this helps
Sam

 
claws2rip:

Public Sub MyMessage(ByVal strMessage As String)
Dim sJavaScript As String
dim Response as System.Web.UI.HtmlTextWriter
sJavaScript = &quot;<script language=javascript>&quot;
sJavaScript &= &quot;alert('&quot; & strMessage & &quot;');&quot;
sJavaScript &= &quot;</script>&quot;
Response.Write(sJavaScript)
' Error Response is not declared.
end sub


 
You can also set the code behind of your pages to inherit from the class Sam suggests, meaning that you don't have to instantiate the class every time you want the functionality; its just part of your page's code behind.

D'Arcy
 
Webforms by default inherit System.Web.UI.Page

Public Class IClaimNotes
Inherits System.Web.UI.Page
End Class
I can not use another I Inherit statement. Do I have to use an Interface to implement Multiple Inheritance
 
Code Behind Class1
Dim s As String = Nothing
Dim Response As HttpResponse
'// Script Header
s += &quot;<Script>&quot;
s += &quot;var hwnd = window.open('send.htm', 'hp','top=250, width=388, height=327, left=400, titlebar=no, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');&quot;
s += &quot;</Script>&quot;
'//Execute Function
Response.Write(s)

Code Behind WebForm
Dim send As Class1 = New Class1()
send.MyMessage()

Error
[NullReferenceException: Object reference not set to an instance of an object.]
My_Web_Client.Class1.MyMessage() +50
 
Shangrilla:

you're right, by default Webforms inherit System.Web.UI.Page.

So what you do is create a base class of your own, that has all the functions you want to have available to all your pages, and have that class inherit system.web.ui.page. Then, in your webform code behind, you change your referene statement to reference your base class instead.
i.e.

Public Class test
Inherits System.Web.UI.Page

Public Function HelloWorld() As String
HelloWorld = &quot;HelloWorld&quot;
End Function
End Class

Public Class WebForm1
Inherits test

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Response.Write(Me.HelloWorld)
End Sub

End Class

This has been tested and verified.

D'Arcy
 
Thanks JFrost.

I ended up putting the following code in Application_BeginRequest() in Global.asax file and that resolved my problem. Thanks for your input everyone.

Dim s As String = Nothing
'// Script Header
s += &quot;<Script>&quot;
s += &quot;var hwnd = window.open('send.htm', 'hp','top=250, width=388, height=327, left=400, titlebar=no, location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');&quot;
s += &quot;</Script>&quot;
'//Execute Function
Response.Write(s)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top