UpdatePanel in infine loop waiting for a session variable
<p>I'm building a site in ASP.Net, which when it first loads, needs to do a browser check.</p>

<p>I do this using document.DocumentMode Please don't tell me about the other methods for this, I know them, and they don't work.  </p>

<p>Ok.</p>

<p>So I have the following javascript called when my Master page loads.  This goes off and sets a sessions variable on another page.  The issue i'm having is that sometimes the page gets stuck into an infinite loop.  I can repliate it by first having my site open, and then republishing it to the server.  When I refresh the page, it launches into the infinite loop.. It however also does it randomly, and the only way to fix it is to close the browser and open it again.. </p>

<pre><code>function myFunc() {
        var xhr = new XMLHttpRequest();
        var docmod = document.documentMode;
        xhr.open("GET", "setResponseHeader.aspx?mode=" + docmod);
        xhr.send();
        var mySesh ="&lt;%= Session["sessResp"] %&gt;";

        if (mySesh == "") 
        {
            __doPostBack('&lt;%= AJAXUpdPan %&gt;', '');
        }
    }
</code></pre>

<p>What I am thinking is somehow place a counter that will trigger after say 5 failed postbacks and stop, but my javascript skills aren't up to scratch for that.. Can anyone help?</p>

<p><em>EDIT</em>
the javascript is called as follows </p>

<pre><code>&lt;body onload="myFunc()"&gt;
&lt;form runat="server"&gt;

&lt;div class="page"&gt;
</code></pre>

<p>here is the update panel</p>

<pre><code>            &lt;asp:ScriptManager ID="ScriptManager1"
                           runat="server" /&gt;

            &lt;asp:UpdatePanel ID="AJAXUpdPan" runat="server"&gt;
                &lt;ContentTemplate&gt;
                &lt;p align="right"&gt;
                    You are currently logged in as &lt;asp:Label ID="lbl_CurrentUser" runat="server" Text="User"&gt;&lt;/asp:Label&gt;&lt;/p&gt;
                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;
</code></pre>

<p>It is working.. It just seems that sometimes it doesn't.. I'm am beginning to suspect it is an issue with using the session variable.. When I publish the site, does it destroy the session or something to that effect?  I think the session might be timing out sometimes, thus causing the random issue.. I have turned up the session timeout to 3600 minutes from 30 minutes.. Will test tomorrow to see if it works.. The publish issue still baffles me though.. </p>
