M
Microsoft News
What I have is a message box that pops up. It is another browser window.
The code is a general function that you pass message, title and a key to.
The box works great except, that if you are on a page, get the message box,
then click ok on the message box go to another page and then back to the
first page. The message box pops up again. It is almost like the history
or cache still has information about the state and that it knows that
message box was popped up shortly before going to the other page and back.
I was looking for a way to stop this.
Example, I check a result and if ok display a message box. then when the
user clicks ok on the message box and fix the result then I redirect them to
another page. Now if they hit the back button then the Message box pops
back up as if it was still in the cache, as if it got loaded again.
If lnResult <> 0 Then
lblMsg.Text = " Authorization Code not valid, check the
company correct code."
ONSMsgBox("No matching Company Authorization Code",
"Error Getting the company info", "btnEnter_Click")
Else
Session("CompanyList") = lobjCompanyInfos
lblMsg.Text = ""
Try
Response.Redirect("information.aspx")
Catch ex As System.Threading.ThreadAbortException
'Eat the exception, Microsoft bug with Redirect
End Try
End If
Below is the code for the message box function that is on the page, the call
it makes to Page. RegisterStartupScript to create the pop up message box,
the HTML code for the message page, and the load of the message page.
Public Sub ONSMsgBox(ByVal psMsg As String, ByVal psTitle As String,
ByVal psKey As String)
Dim lutMsgBox As MsgBox
Try
lutMsgBox.Message = psMsg
lutMsgBox.Title = psTitle
Session("MessageBox") = lutMsgBox
Page.RegisterStartupScript(psKey, DisplayMessage)
Catch ex As Exception
WriteException("ONSMsgBox Exception", ex.Message &
ex.StackTrace)
End Try
End Sub
Inside this I call display message that calls my ASP.Net message box form
and creates it
Public Function DisplayMessage() As String
Dim lobjPopupScript As String = "<script language='javascript'>" & _
"window.open('ONSMsgBox.aspx', 'ONSMsgBoxPopUp', 'Top=100,
Left=100, " & _
"width=450, height=175, menubar=no, resizable=no')" & _
"</script>"
Return lobjPopupScript
End Function
Now the ONSMsgBox is simple page:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="ONSMsgBox.aspx.vb" Inherits="OrionWebSite.ONSMsgBox" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title runat="server" id="MsgBoxTitle">ONSMsgBox</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="orion_styles.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="lblMsg" style="Z-INDEX: 101; LEFT: 24px; POSITION:
absolute; TOP: 24px" runat="server"
Width="416px" Height="88px" CssClass="bodytext">Label</asp:label><INPUT
style="Z-INDEX: 102; LEFT: 200px; WIDTH: 66px; POSITION: absolute; TOP:
120px; HEIGHT: 24px"
type="button" value="Close" onclick="javascript:window.close();"></form>
</body>
</HTML>
and the only code is in the page_load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
wutMsgBox = CType(Session("messageBox"), MsgBox)
MsgBoxTitle.InnerText = wutMsgBox.Title
lblMsg.Text = wutMsgBox.Message
End Sub
The code is a general function that you pass message, title and a key to.
The box works great except, that if you are on a page, get the message box,
then click ok on the message box go to another page and then back to the
first page. The message box pops up again. It is almost like the history
or cache still has information about the state and that it knows that
message box was popped up shortly before going to the other page and back.
I was looking for a way to stop this.
Example, I check a result and if ok display a message box. then when the
user clicks ok on the message box and fix the result then I redirect them to
another page. Now if they hit the back button then the Message box pops
back up as if it was still in the cache, as if it got loaded again.
If lnResult <> 0 Then
lblMsg.Text = " Authorization Code not valid, check the
company correct code."
ONSMsgBox("No matching Company Authorization Code",
"Error Getting the company info", "btnEnter_Click")
Else
Session("CompanyList") = lobjCompanyInfos
lblMsg.Text = ""
Try
Response.Redirect("information.aspx")
Catch ex As System.Threading.ThreadAbortException
'Eat the exception, Microsoft bug with Redirect
End Try
End If
Below is the code for the message box function that is on the page, the call
it makes to Page. RegisterStartupScript to create the pop up message box,
the HTML code for the message page, and the load of the message page.
Public Sub ONSMsgBox(ByVal psMsg As String, ByVal psTitle As String,
ByVal psKey As String)
Dim lutMsgBox As MsgBox
Try
lutMsgBox.Message = psMsg
lutMsgBox.Title = psTitle
Session("MessageBox") = lutMsgBox
Page.RegisterStartupScript(psKey, DisplayMessage)
Catch ex As Exception
WriteException("ONSMsgBox Exception", ex.Message &
ex.StackTrace)
End Try
End Sub
Inside this I call display message that calls my ASP.Net message box form
and creates it
Public Function DisplayMessage() As String
Dim lobjPopupScript As String = "<script language='javascript'>" & _
"window.open('ONSMsgBox.aspx', 'ONSMsgBoxPopUp', 'Top=100,
Left=100, " & _
"width=450, height=175, menubar=no, resizable=no')" & _
"</script>"
Return lobjPopupScript
End Function
Now the ONSMsgBox is simple page:
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="ONSMsgBox.aspx.vb" Inherits="OrionWebSite.ONSMsgBox" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title runat="server" id="MsgBoxTitle">ONSMsgBox</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="orion_styles.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="lblMsg" style="Z-INDEX: 101; LEFT: 24px; POSITION:
absolute; TOP: 24px" runat="server"
Width="416px" Height="88px" CssClass="bodytext">Label</asp:label><INPUT
style="Z-INDEX: 102; LEFT: 200px; WIDTH: 66px; POSITION: absolute; TOP:
120px; HEIGHT: 24px"
type="button" value="Close" onclick="javascript:window.close();"></form>
</body>
</HTML>
and the only code is in the page_load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
wutMsgBox = CType(Session("messageBox"), MsgBox)
MsgBoxTitle.InnerText = wutMsgBox.Title
lblMsg.Text = wutMsgBox.Message
End Sub