Link to home
Start Free TrialLog in
Avatar of GlobexCorp
GlobexCorp

asked on

IFrame And Session Variable problem

Hi I wrote an application in VB.NET. The Main page is a HTML page with an iFrame. The IFrame then loads up the first Page Visitors.aspx. It contains an arraylist of employee details. The Page automatically gets refreshed every 10 seconds using this line of HTML code: <meta http-equiv="refresh" content="10" />

I use a session variable then Session("VisitorCount") to hold a count of how many times the page is refreshed so I can then move onto position 2 of the arraylist and loop through until all of the employee details are displayed once it reaches the end it then redirects onto a second page which does a similar thing and then redirects back to the first page so I need a constant loop between the 2 pages. It loops through the 2 pages the first time fine then the 2nd time round it loops through the 2 pages once it has gone through the 2nd page twice it should redirect back to the first page but it then loads the page twice for some reason and gets stuck in an infinite loop. Any ideas how I can resolve this or an easier way to do this?
Public Partial Class Visitors
    Inherits System.Web.UI.Page
 
    Dim mdbLoc As New FunctionLibrary.sqlFunctions
    Dim gen As New FunctionLibrary.GeneralFunctions
    Dim clsAppointments As New HRMS.Appointments
    Dim intVisitorCount As Integer
    Dim fromDate As Date = CDate("01/9/2008") 'DateTime.Now
    Dim todate As Date = DateTime.Now.AddDays(5)
 
 
    'Testing returns a count of zero
    'Dim visitorInfo As ArrayList = mdbLoc.GetRows("SELECT EmployeeID,VisitorNames,Jobtitle,Company,Visiting,ArriveDate,DepartDate,VisitorID FROM VISITORS WHERE EmployeeID = 32423423432423432423")
    'Dim visitorInfo As ArrayList = mdbLoc.GetRows("SELECT EmployeeID,VisitorNames,Jobtitle,Company,Visiting,ArriveDate,DepartDate,VisitorID FROM ODWYERS.CookIreland.dbo.Visitors WHERE (ARRIVEDATE<='" & fromDate.ToString("MM-dd-yyyy") & "' AND DEPARTDATE>='" & fromDate.ToString("MM-dd-yyyy") & "') OR (ARRIVEDATE<='" & todate.ToString("MM-dd-yyyy") & "' AND DEPARTDATE>='" & todate.ToString("MM-dd-yyyy") & "') OR (ARRIVEDATE>='" & fromDate.ToString("MM-dd-yyyy") & "' AND DEPARTDATE<='" & todate.ToString("MM-dd-yyyy") & "')")
    Dim visitorInfo As ArrayList = mdbLoc.GetRows("SELECT EmployeeID,VisitorNames,Jobtitle,Company,Visiting,ArriveDate,DepartDate,VisitorID FROM ODWYERS.CookIreland.dbo.VISITORS")
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        If visitorInfo.Count = 0 Then
            Response.Write("<script>parent.document.all.IF.src = 'NewStarters.aspx';</script>")
        Else
            intVisitorCount = System.Web.HttpContext.Current.Session("VisitorCount")
            If intVisitorCount > 1 Then 'visitorInfo.Count - 1 Then
                intVisitorCount = 0
                System.Web.HttpContext.Current.Session("VisitorCount") = intVisitorCount
                Response.Write("<script>parent.document.all.IF.src = 'Noticeboards.aspx';</script>")
            Else
                GetVisitors()
            End If
        End If
 
    End Sub
 
    Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error
        gen.DoError(Me)
    End Sub
 
    Protected Sub JavascriptAlertSetHeader(ByVal strMsg As String)
        Dim headerText As String = "<script language='javascript'>setHeader('" & strMsg & "')</script>"
        Page.ClientScript.RegisterStartupScript(GetType(Page), "PopupScript", headerText)
    End Sub
 
    Private Sub GetVisitors()
 
        JavascriptAlertSetHeader("Visitors")
        'Dim fromDate As Date = "12/9/2008"
        'Dim todate As Date = DateAdd(DateInterval.Day, 5, fromDate)
 
        lblFirstVisitor.Text = System.Web.HttpContext.Current.Session("VisitorCount") + 1
        lblLastVisitor.Text = visitorInfo.Count
        Dim tr As New TableRow
        'Detail.InnerText = "(" & visitorInfo.Count & " listed)"
        If visitorInfo.Count > 0 Then
            'For i = Session("VisitorCount") To 2
            Dim td As New TableCell
            Dim tab As New Table
            '<table cellpadding=3 class=fieldname border=0 style='width:280px'>
            If visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(0) > 0 Then
                td.Text = "<tr><td rowspan=7 style='width:10px'><img height=339 width=255 src=hrms/hrms/displayimage.aspx?id=" & visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(0) & "></td>"
            Else
                td.Text = "<tr><td rowspan=7 style='width:10px;padding-top:6px;' valign=top><img src='Graphics/blankphoto.jpg' height=339 width=255></td>"
            End If
 
            td.Text = td.Text & "<tr><td><b>" & visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(1) & "</b></td></tr>" & _
                      "<tr><td>" & visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(2) & "</td></tr>" & _
                      "<tr><td>" & visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(3) & "</td></tr>" & _
                      "<tr><td>Visiting " & visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(4) & "</td></tr>" & _
                      "<tr><td>From: " & gen.fDate(visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(5)) & " to " & gen.fDate(visitorInfo(System.Web.HttpContext.Current.Session("VisitorCount"))(6)) & "</td></tr>"
 
            td.Text = td.Text & "<tr><td>&nbsp;</td></tr>"
 
            tr.Cells.Add(td)
        Else
            Dim td As New TableCell
            Dim tab As New Table
 
            td.Text = "No Visitors This Week"
            tr.Cells.Add(td)
        End If
        MainTab.Rows.Add(tr)
        intVisitorCount += 1
        System.Web.HttpContext.Current.Session("VisitorCount") = intVisitorCount
 
    End Sub
End Class
 
 
 
Public Partial Class Noticeboards
    Inherits System.Web.UI.Page
    Private sql As New FunctionLibrary.sqlFunctions
    Private gen As New FunctionLibrary.GeneralFunctions
    Dim intMessageCount As Integer = 0
    'Testing Returns A Count Of Zero
    'Dim rlist As ArrayList = sql.GetRows("SELECT TOP (100) PERCENT Users.UserFullName, Category.Category, Messages.CreatedDate, Messages.Subject, Messages.Message, Messages.MessageID, Messages.CreatedBy, Messages.CategoryID, Messages.LastUpdate, Users.Role + Messages.CreatedBy AS CanEdit FROM ODWYERS.Noticeboards.dbo.Messages Messages INNER JOIN ODWYERS.Noticeboards.dbo.Category Category ON Messages.CategoryID = Category.CategoryID INNER JOIN ODWYERS.Noticeboards.dbo.Users Users ON Messages.CreatedBy = Users.EmployeeID WHERE Category.Category = 'TEST' ORDER BY Messages.MessageID")
 
 
    Private Sub CreateMessage_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
        gen.DoError(Me)
    End Sub
    Const ADMIN_ROLE = 1
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        Dim rlist As ArrayList = sql.GetRows("SELECT TOP (100) PERCENT Users.UserFullName, Category.Category, Messages.CreatedDate, Messages.Subject, Messages.Message, Messages.MessageID, Messages.CreatedBy, Messages.CategoryID, Messages.LastUpdate, Users.Role + Messages.CreatedBy AS CanEdit FROM ODWYERS.Noticeboards.dbo.Messages Messages INNER JOIN ODWYERS.Noticeboards.dbo.Category Category ON Messages.CategoryID = Category.CategoryID INNER JOIN ODWYERS.Noticeboards.dbo.Users Users ON Messages.CreatedBy = Users.EmployeeID ORDER BY Messages.MessageID")
        If rlist.Count = 0 Then
            Response.Write("<script>parent.document.all.IF.src = 'Visitors.aspx';</script>")
        Else
 
            intMessageCount = System.Web.HttpContext.Current.Session("MessageCount")
            If intMessageCount > 1 Then 'visitorInfo.Count - 1 Then
                intMessageCount = 0
                System.Web.HttpContext.Current.Session("MessageCount") = intMessageCount
                Response.Write("<script>parent.document.all.IF.src = 'Visitors.aspx';</script>")
            Else
                getNotices()
            End If
        End If
    End Sub
 
    Protected Sub JavascriptAlertSetHeader(ByVal strMsg As String)
 
        Dim headerText As String = "<script language='javascript'>setHeader('" & strMsg & "')</script>"
 
        Page.ClientScript.RegisterStartupScript(GetType(Page), "PopupScript", headerText)
 
    End Sub
    Public Sub getNotices()
        JavascriptAlertSetHeader("Noticeboards")
        
        Dim rlist As ArrayList = sql.GetRows("SELECT TOP (100) PERCENT Users.UserFullName, Category.Category, Messages.CreatedDate, Messages.Subject, Messages.Message, Messages.MessageID, Messages.CreatedBy, Messages.CategoryID, Messages.LastUpdate, Users.Role + Messages.CreatedBy AS CanEdit FROM ODWYERS.Noticeboards.dbo.Messages Messages INNER JOIN ODWYERS.Noticeboards.dbo.Category Category ON Messages.CategoryID = Category.CategoryID INNER JOIN ODWYERS.Noticeboards.dbo.Users Users ON Messages.CreatedBy = Users.EmployeeID ORDER BY Messages.MessageID")
        Dim myParam As FunctionLibrary.sqlFunctions.SP_Params_AnyType
        Dim myArray As New ArrayList
 
        lblCurrentMessage.Text = intMessageCount + 1
        lblMessageCount.Text = rlist.Count
 
        If rlist.Count > 0 Then
 
            Dim lastUpdatedFulDate As String = rlist(Session("MessageCount"))(8)
            Dim createdFullDate As String = rlist(Session("MessageCount"))(2)
 
            Dim createdDate As String = createdFullDate.Substring(0, 10)
            Dim createdTime As String = createdFullDate.Substring(10, 9)
 
            Dim lastUpdatedDate As String = lastUpdatedFulDate.Substring(0, 10)
            Dim lastUpdatedTime As String = lastUpdatedFulDate.Substring(10, 9)
 
            myParam.Name = "@MessageID"
            myParam.Type = Data.SqlDbType.Int
            myParam.Value = rlist(Session("MessageCount"))(5)
            myArray.Add(myParam)
 
            Dim imagelist As New ArrayList
            imagelist = sql.RunSPQuery("ReturnImageNames", myArray)
 
            If imagelist.Count = 2 Then
                hdnFirstImagePath.Value = imagelist(0)(0)
                hdnSecondImagePath.Value = imagelist(1)(0)
            End If
 
            If imagelist.Count = 1 Then
                hdnFirstImagePath.Value = imagelist(0)(0)
                hdnSecondImagePath.Value = imagelist(0)(0)
            End If
 
            If imagelist.Count = 0 Then
                hdnFirstImagePath.Value = "Graphics/blankphoto.jpg"
                hdnSecondImagePath.Value = "Graphics/blankphoto.jpg"
            End If
 
            PostedBy.Text = rlist(Session("MessageCount"))(0)
            lblCreatedDate.Text = createdDate
            lblCreatedTime.Text = createdTime
            lblLastUpdatedDate.Text = lastUpdatedDate
            lblLastUpdatedTime.Text = lastUpdatedTime
            Subject.Text = rlist(Session("MessageCount"))(3)
            hdnMessage.Value = (rlist(Session("MessageCount"))(3))
            'hdnMessage.Value = imagelist(0)(0)
            intMessageCount = intMessageCount + 1
            Session("MessageCount") = intMessageCount
 
        Else
        End If
    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of OBonio
OBonio
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GlobexCorp
GlobexCorp

ASKER

Hi I managed to resolve the issue by changing the page redirects from:

Response.Write("<script>parent.document.all.IF.src = 'Visitors.aspx';</script>")

to:

Response.Redirect("Visitors.aspx").

 Im still curious though if anybody knows why this javascript would have caused the page to load twice the 2nd time round?

Thanks,
Gary.