Avatar of capsoftuk
capsoftuk
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

iFrame not functioning properly

I am trying to figure out this problem that I am having in regards to my software.

I have an aspx (answersummary.aspx) page that takes a post of XML data, parses the xml and displays the parsed details. The returned page contains some JavaScript and css.

I want to display the return from this page in an iframe on another aspx page, except I actually want to have 2 iframes, and each iframe will display answersummary.aspx but with different XML posted to each page.

The javascript file writes out a seperate iframe (which I cannot remove).

Right now I am trying implement just one of the iframes. Using ASP.NET I am using a single literal object and setting the text of the literal to the iframe. The text of the literal is set by the getFrameOne method:

        protected string getFrameOne(string result)    
        {  
           string frame = "<iframe id=\"frameOne\" src=\"about:blank\"></iframe>";
           return frame;
        }

The contents of the iframe is set seperately using javascript called which is being set inside the literal string using the following javascript code:

        var testFrame = document.getElementById("myFrame");
        var doc = testFrame.contentDocument;
        if (doc == undefined || doc == null)
            doc = testFrame.contentWindow.document;
        doc.open();
        doc.write(val);
        doc.close();

The variable val is the output of the content from the answersummary.aspx page.  The reason why I am coding the iframe this way is because the call to the answersummary.aspx page requires the XML string to be posted to the page.  I write out the response of the page by using the following:

                StreamWriter myWriter = null;
                HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(sURL);
                objRequest.Method = "POST";
                objRequest.ContentLength = strPost.Length;
                objRequest.ContentType = "application/x-www-form-urlencoded";

                try
                {
                    myWriter = new StreamWriter(objRequest.GetRequestStream());
                    myWriter.Write(strPost);
                }
                catch (Exception ex)
                {
                    TextBox1.Text = string.Format("Error: {0}", ex.Message);
                }
                finally
                {
                    myWriter.Close();
                }

                HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                {
                    result = sr.ReadToEnd();

                    // Close and clean up the StreamReader
                    sr.Close();
                }

Now the problem is when I write the response of the answersummary.aspx page out to the literal object, it kind of crashes internet explorer.  It does render what I need it to but the window becomes unresponsive.  The scroll bar keeps on loading as if the page is infintely long but I can't scroll down.  So it seems to me that something is running in an infinte loop but I am unsure as why this is happening.

I have taken the response of the seperate aspx page out and saved into a seperate html file without the external iframe.  When I open this file directly without putting it in an iframe it loads fine.  It did not crash and I did not have any problems.  So I am not sure why this is occuring.

Any help or suggestions for alternative approaches would be greatly appreciated.

Jeff
Editors IDEsJavaScriptASP

Avatar of undefined
Last Comment
capsoftuk

8/22/2022 - Mon