Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

A frame in a frameset may become blank on an ASP page or in an ASP.NET application


View products that this article applies to.

Symptoms

If you programmatically call the submit function in a form, and the form is on a page in a frameset, the response may not appear. Instead, the frame may become blank.

Typically, this problem occurs on an ASP page or in a Microsoft ASP.NET application that has the postback function enabled on a control that contains items that the user selects, such as ListBox control or a DropDownList control. This problem occurs when the user changes the selected item in the control.

↑ Back to the top


Cause

This problem is a timing bug. This problem may occur if a call is made to the submit function from an onchange event handler at the same time that a response for a POST request is received.

In ASP.NET, this problem may occur if the user clicks a new item in the ListBox control or in the DropDownList control at the same time that the response for the previous postback request is received.

↑ Back to the top


Workaround

To work around this problem, use one of the following methods:
  • Workaround 1
    Wait until the onchange event has completed and then call the submit function later by using a Timeout function.
  • Workaround 2
    Prevent the user from performing another POST request by changing the HTML page in the onbeforeunload event.
For more information about how to use these workarounds, see the "More information" section.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

↑ Back to the top


More information

Steps to reproduce the problem in an ASP page

This example reproduces the problem and the workarounds in an ASP page.
  1. Use the following sample code to create an HTML frameset page that is named Frameset.htm:
    <html>
    <frameset cols="110,*">
    	<frame src="about:blank">
    	<frame src="frame.asp">
    </frameset>
    </html>
    
  2. Use the following sample code to create an HTML frame page that is named Frame.asp:
    <%
    ' This delay is introduced to enable the user to generate another 
    ' post at the same time that this response is received.
    dim y
    y = 0
    for x = 1 to 100000 ' This setting can be modified to adjust the delay.
      y = y + x/10
    next
    %>
    <html>
    <body onbeforeunloadx="Workaround2()">
    <form method="post" action="frame.asp" id="form1">
    	<select name="ListBox1" size="4" onchange="form1.submit()" id="ListBox1">
    		<option value="Item1">Item1</option>
    		<option value="Item2">Item2</option>
    		<option value="Item3">Item3</option>
    	</select>
    </form>
    <script language="javascript">
    function Workaround1()
    {
    	setTimeout("form1.submit()", 1);
    }
    function Workaround2()
    {
    	document.body.innerHTML = "Waiting for response.";
    }
    </script>
    </body>
    </html>
    
    Note In this sample code, the onbeforeunload event handler is misspelled as "onbeforeunloadx" to disable the workaround for now.
  3. Save the files that you created in steps 1 and 2 to a Web server.
  4. In your Web browser, view the Frameset.htm file.
  5. Click various items in the list box. Notice that every click triggers an onchange event, and every onchange event causes a POST request to be sent to the server again through the form1.submit function call.

    If you click an item in the list box at the same time that a response is received, the frame becomes blank.
  6. Implement one of the following workarounds at a time:
    • Workaround 1
      To implement the first workaround, modify the onchange event handler to call the Workaround1 function. This workaround creates a Timeout function. This Timeout function allows the submit call to be made after the onchange event has completed.
    • Workaround 2
      To implement the second workaround, rename the "onbeforeunloadx" event handler as onbeforeunload. After you rename the onbeforeunload event handler, the event handler calls the Workaround2 function. The second workaround changes the contents of the page. This change prevents the user from clicking anything until the response has been received and has been rendered.

Steps to reproduce the behavior in ASP.NET

This example reproduces the problem in an ASP.NET application.
  1. Create an ASP.NET application. You can use either Visual Basic .NET or Visual C# .NET. However, these steps use Visual C# .NET.

    By default, a file that is named WebForm1.aspx is created.
  2. Modify the HTML in the WebForm1.aspx file so that it contains a frameset. In this frameset, one frame points to the about:blank page, and the other frame points to a new form that you will create in step 3. To do this, add the following code to the WebForm1.aspx file:
      	<frameset cols="110,*">
    		<frame src="about:blank" scrolling="no" frameborder="yes">
    		<frame src="WebForm2.aspx" scrolling="no" frameborder="yes">
    	</frameset>
  3. Create a new ASP.NET form that is named WebForm2.aspx.
  4. Add a Web Form ListBox control. Enable the AutoPostBack property of the ListBox control.
  5. Add three list items to the ListBox control. To do this, edit the Items property of the ListBox control.
  6. To simulate the delay, add code in the Page_Load event handler of the WebForm2.aspx file to delay the response for 500 milliseconds (msec).
    		
    using System.Threading;
    ...
    	public class WebForm2 : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.ListBox ListBox1;
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			Thread.Sleep(500);
    		}
    ...
    
  7. Build the project, and then open the WebForm1.aspx file in your Web browser.
If you click various list box items at exactly the correct time, the frame becomes blank. The timing of this click is approximately 500 msec after the last click, plus any network delays.

↑ Back to the top


Properties

Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.

↑ Back to the top


Keywords: KB840545, kbbug, kbpending

↑ Back to the top

Article Info
Article ID : 840545
Revision : 1
Created on : 4/27/2004
Published on : 4/27/2004
Exists online : False
Views : 278