views:

45

answers:

2

I have a website that upon a person going to it, it checks a timestamp on the database. If the timestamp is over 4 hours old then it opens a popup winodw that runs a database import/update sub that updats the database. Then closes itself out afterward.

The reasoning for doing it this way is it allows the person browsing to continue about their business while a seperate window takes care of the update.

Right now this popup appears as the focus. Is there a way to make the popup load behind the current browser window as to not intrude the users navigation?

Here is the page_load sub of the main window.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        Dim connStr As String = ConfigurationManager.ConnectionStrings("SNA_TRT").ConnectionString
        Dim sqlConn As SqlConnection
        sqlConn = New SqlConnection(connStr)

        sqlConn.Open()

        Dim strSQL As String = "SELECT TOP 1 [ID], [LASTREFRESH], [BYWHO] FROM [TRT_db_timer] ORDER BY [ID] Desc "
        Dim cmd As New SqlCommand(strSQL, sqlConn)
        Dim dr As SqlDataReader = cmd.ExecuteReader()

        Dim lastupdate As DateTime
        Dim currenttime As DateTime = Now()

        While dr.Read()
            lastupdate = Convert.ToDateTime(dr(ClearNullDs("LASTREFRESH")))
        End While
        dr.Close()
        sqlConn.Close()

        Dim ts As TimeSpan = currenttime.Subtract(lastupdate)
        Dim dbspan As String = ts.TotalMinutes.ToString()

        Dim dsinceup As Integer = ts.Days.ToString + 1

        'MsgBox(lastupdate)
        'MsgBox(currenttime)
        'MsgBox(dbspan)

        If dbspan > 240 Then
            bodytag.Attributes.Add("onload", "window.open('/trt/admin/importnotice.aspx?DAYS=" & dsinceup & "',null,'height=150, width=350,status=yes, resizable=no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
        End If
    End If
End Sub
+1  A: 

If you want the update to happen when the user arrives at the site, use AJAX or a hidden iframe. If you want the update to happen every X hours no matter if the user visits the site, use a CRON job. Popping up a window to do this will aggravate the user.

Carl
I thought about a hidden frame but if the update is started and the user navigates to another page on the site with the update is still in progress doesn't that end the process?
Kardsen
It sounds like you need an asynchronous process on the server. That way a call could be made and nearly immediately returned but the job would continue running no matter if the user navigated away. A popup window also stands the chance of getting snagged by popup blockers.
Carl
A: 

There are definitely better way to do this (like ajax).

But to answer your question:

function loadpopunder(){
    var popunder=window.open(/* popup window parameters */);
    popunder.blur();
    window.focus(); // focuses the main window.
}
David Murdoch
Well, I know it may not be the best way to do this but thnks!I was able to incorporate this in the page and then in the code behind addedbodytag.Attributes.Add("onload", "loadpopunder(" ")I would 1 up your answer, but sadly I am not high enough ranked yet.
Kardsen