Steps to reproduce the problem in an ASP page
This example reproduces the problem and the workarounds in an ASP page.
- 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>
- 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. - Save the files that you created in steps 1 and 2 to a Web server.
- In your Web browser, view the Frameset.htm file.
- 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. - 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.
- 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. - 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>
- Create a new ASP.NET form that is named WebForm2.aspx.
- Add a Web Form ListBox control. Enable the AutoPostBack property of the ListBox control.
- Add three list items to the ListBox control. To do this, edit the Items property of the ListBox control.
- 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);
}
...
- 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.