Total user count in Web-application

K

KS

I have made a WebForm with log ON/OFF off users.

There is a label that shows the total count off users logged on stored in
Application("UserCount")

It works fine if the users logs out WITH THE LOG-OUT BUTTON, but what if a
user "logs out" by closing with the X-button ?

If I count down the Application("UserCount") in UNLOAD or DISPOSE I get a
spoky reaction in Application("UserCount") - it just counts wrong !

What can I do to catch (and count down the total users) that a user "logs
out" by using the X-button ?

KS, Denmark
 
S

Steve C. Orr [MVP, MCSD]

You can use a counter in your Global.asax, in the Session_Start and
Session_End events to get a rough idea of how many people are on your site.
There is no good way to get a real-time precise count, however, due to the
stateless nature of the internet.
 
D

Do Quyet Tien

And mean that your counter only updated when the session timed-out :), again, no better way at this time.

Tiendq,
(e-mail address removed)
 
K

KS

Steve C. Orr said:
You can use a counter in your Global.asax, in the Session_Start and
Session_End events to get a rough idea of how many people are on your site.
There is no good way to get a real-time precise count, however, due to the
stateless nature of the internet.
I seems as though my code in Global.asax Session_End is NOT executed.

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
If CType(Session("UserName"), String) <> "" OrElse Not
(Session("UserName") Is Nothing) Then
Application("AllUsers") = CType(Application("AllUsers"), Integer) - 1
End If
End Sub

IS the sub Session_End REALLY fired when the user closes using the
X-button - how can I make shure ?
(a break-point somewhere in the Session_End will NOT do it !)

Should I addhandler or what ?

Another thing - How can I set focus in a textbox at a webform ?

KS, Denmark
 
A

Alvin Bruney [MVP]

Another thing - How can I set focus in a textbox at a webform ?
i use this code generically.

public static void SetInitialFocus(System.Web.UI.Control control)

{

if (control.Page == null)

{

throw new ArgumentException(

"The Control must be added to a Page before you can set the IntialFocus to
it.");

}

if (control.Page.Request.Browser.JavaScript == true)

{

// Create JavaScript

StringBuilder s = new StringBuilder();

s.Append("\n<SCRIPT LANGUAGE='JavaScript'>\n");

s.Append("<!--\n");

s.Append("function SetInitialFocus()\n");

s.Append("{\n");

s.Append(" document.");

// Find the Form

System.Web.UI.Control p = control.Parent;

while (!(p is System.Web.UI.HtmlControls.HtmlForm))

p = p.Parent;

s.Append(p.ClientID);

s.Append("['");

s.Append(control.UniqueID);

// Set Focus on the selected item of a RadioButtonList

System.Web.UI.WebControls.TextBox rbl = control as
System.Web.UI.WebControls.TextBox;

s.Append("'].focus();\n document.all.WaitState.style.display = 'None';\n");

s.Append("}\n");

if (control.Page.SmartNavigation)

s.Append("window.setTimeout(SetInitialFocus, 500);\n");

else

s.Append("window.onload = SetInitialFocus;\n");

s.Append("// -->\n");

s.Append("</SCRIPT>");

// Register Client Script

control.Page.RegisterClientScriptBlock("InitialFocus", s.ToString());

}

}
 
K

KS

!!!!!!!!!! - "aahh - peace og cake !" ;-(

Why not just

<controlID>.Focus

as in Windows Forms ?

KS, Denmark



Alvin Bruney said:
Another thing - How can I set focus in a textbox at a webform ?
i use this code generically.

public static void SetInitialFocus(System.Web.UI.Control control)

{

if (control.Page == null)

{

throw new ArgumentException(

"The Control must be added to a Page before you can set the IntialFocus to
it.");

}

if (control.Page.Request.Browser.JavaScript == true)

{

// Create JavaScript

StringBuilder s = new StringBuilder();

s.Append("\n<SCRIPT LANGUAGE='JavaScript'>\n");

s.Append("<!--\n");

s.Append("function SetInitialFocus()\n");

s.Append("{\n");

s.Append(" document.");

// Find the Form

System.Web.UI.Control p = control.Parent;

while (!(p is System.Web.UI.HtmlControls.HtmlForm))

p = p.Parent;

s.Append(p.ClientID);

s.Append("['");

s.Append(control.UniqueID);

// Set Focus on the selected item of a RadioButtonList

System.Web.UI.WebControls.TextBox rbl = control as
System.Web.UI.WebControls.TextBox;

s.Append("'].focus();\n document.all.WaitState.style.display = 'None';\n");

s.Append("}\n");

if (control.Page.SmartNavigation)

s.Append("window.setTimeout(SetInitialFocus, 500);\n");

else

s.Append("window.onload = SetInitialFocus;\n");

s.Append("// -->\n");

s.Append("</SCRIPT>");

// Register Client Script

control.Page.RegisterClientScriptBlock("InitialFocus", s.ToString());

}

}


--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
KS said:
I seems as though my code in Global.asax Session_End is NOT executed.

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
If CType(Session("UserName"), String) <> "" OrElse Not
(Session("UserName") Is Nothing) Then
Application("AllUsers") = CType(Application("AllUsers"), Integer) - 1
End If
End Sub

IS the sub Session_End REALLY fired when the user closes using the
X-button - how can I make shure ?
(a break-point somewhere in the Session_End will NOT do it !)

Should I addhandler or what ?

Another thing - How can I set focus in a textbox at a webform ?

KS, Denmark
 
G

George

Here's something I found on the Web that I have been using.

Private Sub SetFocus(ByVal ctrl As System.Web.UI.Control)

Dim s As String = "<SCRIPT language='javascript'>document.getElementById('"
& ctrl.ID & "').focus() </SCRIPT>"

RegisterStartupScript("focus", s)

End Sub

George


KS said:
!!!!!!!!!! - "aahh - peace og cake !" ;-(

Why not just

<controlID>.Focus

as in Windows Forms ?

KS, Denmark



Alvin Bruney said:
Another thing - How can I set focus in a textbox at a webform ?
i use this code generically.

public static void SetInitialFocus(System.Web.UI.Control control)

{

if (control.Page == null)

{

throw new ArgumentException(

"The Control must be added to a Page before you can set the IntialFocus to
it.");

}

if (control.Page.Request.Browser.JavaScript == true)

{

// Create JavaScript

StringBuilder s = new StringBuilder();

s.Append("\n<SCRIPT LANGUAGE='JavaScript'>\n");

s.Append("<!--\n");

s.Append("function SetInitialFocus()\n");

s.Append("{\n");

s.Append(" document.");

// Find the Form

System.Web.UI.Control p = control.Parent;

while (!(p is System.Web.UI.HtmlControls.HtmlForm))

p = p.Parent;

s.Append(p.ClientID);

s.Append("['");

s.Append(control.UniqueID);

// Set Focus on the selected item of a RadioButtonList

System.Web.UI.WebControls.TextBox rbl = control as
System.Web.UI.WebControls.TextBox;

s.Append("'].focus();\n document.all.WaitState.style.display = 'None';\n");

s.Append("}\n");

if (control.Page.SmartNavigation)

s.Append("window.setTimeout(SetInitialFocus, 500);\n");

else

s.Append("window.onload = SetInitialFocus;\n");

s.Append("// -->\n");

s.Append("</SCRIPT>");

// Register Client Script

control.Page.RegisterClientScriptBlock("InitialFocus", s.ToString());

}

}


--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
KS said:
"Steve C. Orr [MVP, MCSD]" <[email protected]> skrev i en meddelelse
You can use a counter in your Global.asax, in the Session_Start and
Session_End events to get a rough idea of how many people are on your
site.
There is no good way to get a real-time precise count, however, due
to
the
stateless nature of the internet.

I seems as though my code in Global.asax Session_End is NOT executed.

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
If CType(Session("UserName"), String) <> "" OrElse Not
(Session("UserName") Is Nothing) Then
Application("AllUsers") = CType(Application("AllUsers"),
Integer) -
1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top