PageMethods to retrieve session from page in iframe not working
<p>2 pages. Uploader.aspx and Uploadee.aspx.</p>

<p>Uploadee.aspx is in an iframe on Uploader.aspx.</p>

<p>This is the markup for Uploader.aspx:</p>

<pre><code>    &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Uploader.aspx.cs" Inherits="Uploader" EnableEventValidation="false" %&gt;

    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head runat="server"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script type="text/javascript"&gt;
    function doupload()
    {
        document.getElementById('spFN').innerHTML = 'Document upload in progress.';
        window.frames[0].document.forms[0].submit();

        intervalID = window.setInterval(function ()
        {
            PageMethods.GetUploadStatus(function (result)
            {
                if (result)
                {
                    alert(result.fileNumber);
                    document.getElementById('spFN').innerHTML = 'Uploading file ' + result.fileNumber;
                }
            });
        }, 500);
    }  
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

    &lt;form id="form1" runat="server"&gt;
    &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"&gt;&lt;/asp:ScriptManager&gt;
    &lt;div&gt;
    &lt;span onclick="doupload();"&gt;Try it&lt;/span&gt; &lt;span id="spFN"&gt;&lt;/span&gt;
    &lt;iframe id="uploadFrame" frameborder="0" height="400" width="800" scrolling="yes" src="Uploadee.aspx"&gt;&lt;/iframe&gt;
    &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I am trying to read the value of a session variable from the page in the iframe. Here is the code in the page behind of the page in the iframe (uploadee.aspx).</p>

<pre><code>    public partial class Uploadee : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            for (int i = 0; i &lt; 3; i++)
            {
                Session["FN"] = i.ToString();
                Thread.Sleep(1000);
            }
        }
    }
}
</code></pre>

<p>So, I am in a loop increasing the session variable - Session["FN"] - by 1 each iteration.</p>

<p>In the code behind of the page that contains the iframe, I have this:</p>

<pre><code> #region Web Methods
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static object GetUploadStatus()
{
    string fileNumber = HttpContext.Current.Session["FN"].ToString();
    return new
    {
        fileNumber = fileNumber
    };

}
#endregion
</code></pre>

<p>So, the process is: I click on the 'Try it' span on the containing page - Uploader.aspx - and this calls javascript function doupload()</p>

<p>This submits the form on the page in the iframe. When this form submits, the loop is run that increases the value of the Session["FN"] variable. At the same time, PageMethods.GetUploadStatus should be querying the value of Session["FN"] every 500 milliseconds.</p>

<p>BUT, the only time the alert in PageMethods.GetUploadStatus is shown, is AFTER all the iterations of the loop. It retrieves the value of Session["FN"] okay - but only once and only after the page in the iframe has finished processing.</p>

<p>I keep reading that I should be able to do what I am trying to do ... any help much appreciated. This is driving me nuts. Apologies for length of post.</p>
