A PopUp to show if you have messages waiting.

BluJag

Perch
A PopUp to show if you have messages waiting.

asp.net using VB

If your site allows people to leave messages for yourself or others then you can have a Message Box popping up when you come to one of your web pages - similar to the Private Message popups which happen on this forum when someone has left a PM for you.

1. The message left by a person is stored in a database.
2. The receiving person must have logged in to your site.

Put this asp literal control just beneath the <body> tag in your .aspx page

<body>
<script>
<asp:Literal id="ltlAlert" runat="server"
EnableViewState="False">
</asp:Literal>
</script>


Add this label control to show how many messages a person has. Place it in that part of the page where you want it to appear.

<asp:LinkButton id="lbMessages" runat="server" ToolTip="Click to go to your messages" CausesValidation="False"></asp:LinkButton>

In the .aspx.vb file, put the following in your page load routine

+++++++++++++++++++++++++++++++++++++++++++++++

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


If Not Page.IsPostBack Then
MemberID = CheckCookie() ' routine to check cookie - not shown here.
Viewstate("MEMBERID") = MemberID

'// Note that this code only runs if the page is not a post back. This means it will only run the first time the page appears.

Dim NumberOfMessages As Integer
NumberOfMessages = CheckMessages()
lbMessages.Text = " Messages waiting: " & CStr(NumberOfMessages) & " "
If NumberOfMessages <> 0 Then
lbMessages.BackColor = lbMessages.BackColor.Yellow
lbMessages.ForeColor = lbMessages.ForeColor.Red
lbMessages.Font.Bold = True
lbMessages.BorderColor = lbMessages.BorderColor.Black

Else
lbMessages.BackColor = lbMessages.BackColor.White
lbMessages.ForeColor = lbMessages.ForeColor.Black
lbMessages.Font.Bold = False
lbMessages.BorderColor = lbMessages.BorderColor.White

End If

If NumberOfMessages = 1 Then Say("You have " & CStr(NumberOfMessages) & " message waiting")
If NumberOfMessages > 1 Then Say("You have " & CStr(NumberOfMessages) & " messages waiting")

End If

End Sub

+++++++++++++++++++++++++++++++++++++++++++++++

Private Function CheckMessages() As Integer
'This gets how many messages are waiting for the person.
Dim DB As New Glooper.Helpers
CheckMessages = DB.CheckMessages(CInt(Viewstate("MEMBERID")))

End Function

+++++++++++++++++++++++++++++++++++++++++++++++

Private Sub Say(ByVal Message As String)
' Format string properly
Message = Message.Replace("'", "\'")
Message = Message.Replace(Convert.ToChar(10), "\n")
Message = Message.Replace(Convert.ToChar(13), "")
' Display as JavaScript alert
ltlAlert.Text = "alert('" & Message & "')"
End Sub
+++++++++++++++++++++++++++++++++++++++++++++++

Private Sub GoToMessages()
lbMessages.BackColor = lbMessages.BackColor.White
lbMessages.ForeColor = lbMessages.ForeColor.Black
lbMessages.Font.Bold = False
lbMessages.BorderColor = lbMessages.BorderColor.White

Response.Redirect("read_messages.aspx", True) 'page where you show the actual messages
End Sub

+++++++++++++++++++++++++++++++++++++++++++++++

Private Sub lbMessages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbMessages.Click
GoToMessages()
End Sub

+++++++++++++++++++++++++++++++++++++++++++++++
 
Back
Top