[引文]Problem with DropDownList & Frames
发现FRAME和一些东东冲突已经很长时间了,这里要引述的DropDownList为一,而某三方作的价钱异国间换算不能刷新为一,为增强记忆,重拾旧物。
以下引自:http://www.dotnet247.com/247reference/msgs/40/204635.aspx,这里向原作者致以敬意。
-----------------------------------------------------------------------------------------------------------------------------------------------
I have an ASP.NET web page -- several auto-post back DropDownLists that perform a query against a relatively large database (3 to 4 seconds delay) that repopulate a couple of datagrids, comboboxes and a chart (using dotnetCharting control) on the same page. This works just fine on its own. However, when I integrated the page into the rest of the site, it is then placed inside a frameset. Again, the page seems to work fine EXCEPT under the following circumstances:
1. Select an item in the DropDownList (the query then starts running on the server)
2. While the query is running, drop the list down again, but DON'T select anything.
3. The query stops running, the code on the server side successfully completes, but the page in the frame does not plot
4. After this point, the page in the frame is 'blown' -- it will not replot again, unless you reload page that creates the frameset.
This is completely repeatable. And it does not have a problem if it is not in a frameset.
I have been coding for a long time, but am new to ASP.NET, so apologies if I have committed some obvious error. Thanks in advance for any ideas.
Bob
-----------------------------------------------------------------------------------------------------------------------------------------------
Hi Bob,
Thanks for posting in the community!
From your description, you encountered a strange problem which occured when
you try edit a dropdownlist after it has just been changed and posted back.
That'll cause the page blown, yes?
If there is anything I misunderstood, please feel free to let me know.
You've tried following the steps you provided and did found this problem.
This seems very strange and currently we're
doing further research on this issue so as to find some proper resource to
assist you. In addtion, here is an approach to workaround this problem if
you feel urgent to get rid of this problem:
We can set a flag when the dropdownlist is first time changed, then if next
time a user try to change it, we'll disable it so as to prevent it from
being droped down again. And here is a sample to show this workaround:
-----------------------aspx page----------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DropDownListError</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
<script language=javascript>
function check()
{
if(document.all("hdFlag").value == "1")
{
document.all("lstMain").disabled = true;
}
}
function setflag()
{
document.all("hdFlag").value = "1";
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label><input
type="hidden" id="hdFlag" runat="server" value="0" NAME="hdFlag"></td>
</tr>
<tr>
<td>
<asp:DropDownList id="lstMain" runat="server" AutoPostBack="True">
<asp:ListItem Value="ItemA" Selected="True">ItemA</asp:ListItem>
<asp:ListItem Value="ItemB">ItemB</asp:ListItem>
<asp:ListItem Value="ItemC">ItemC</asp:ListItem>
<asp:ListItem Value="ItemD">ItemD</asp:ListItem>
</asp:DropDownList>
<select ></select>
</td>
</tr>
</table>
</form>
</body>
</HTML>
-------------------code behind page class-------------------
public class DropDownListError : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList lstMain;
protected System.Web.UI.HtmlControls.HtmlInputHidden hdFlag;
protected System.Web.UI.WebControls.Label lblMessage;
private void Page_Load(object sender, System.EventArgs e)
{
lstMain.Attributes.Add("onchange","setflag();");
lstMain.Attributes.Add("onmousedown","check();");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lstMain.SelectedIndexChanged += new
System.EventHandler(this.lstMain_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void lstMain_SelectedIndexChanged(object sender, System.EventArgs
e)
{
System.Threading.Thread.Sleep(1000*4);
lblMessage.Text = "SelectIndex is changed to " + lstMain.SelectedIndex +
"at " + DateTime.Now.ToLongTimeString();
hdFlag.Value = "0";
}
}
----------------------------------------------
Please try putting the above sample into a frameset to see whether it works
for you. In the meantime, if you have any questions, please feel free to
post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
-----------------------------------------------------------------------------------------------------------------------------------------------
Yes, the page is 'blown' if you just drop-down the list while the previous request is processing-- you do not even have to make another selection. You run the same page, not in a frame, and the problem disappears. I might try the work-around in the short run, but I'd like to figure out what is causing this so I can avoid it in the future. Drop me a private email if you'd like the URL's that generate the problem.
Thanks for any further help.
Bob
-----------------------------------------------------------------------------------------------------------------------------------------------
Hi Bob,
What do you mean exactly when you said the page is "blown"? Can you give
more specific?
thank you,
Amy
This posting is provided "AS IS" with no warranties, and confers no rights.
-----------------------------------------------------------------------------------------------------------------------------------------------
The page comes back completely blank. I used one of my MSDN subscription support calls, and it turns out that this is a known bug with IE, and it is not scheduled to be fixed until the Longhorn release :(
They suggested a similar fix to Alan's, except rather than disabling control, they simply added a delay. I think I like Steve's answer better.
Thanks to everyone for your help.
Bob
-----------------------------------------------------------------------------------------------------------------------------------------------
For the sake of completeness, here is the reply I got from the ASP.NET support folks:
Subject: SRX040209600450
*** Problem Description ***
Customer has an asp.net application with a dropdown menu and enable autopostback in
a frame
When users selects an item, it will do a postback to server. Before the postback
completes and the page refreshes, click the dropdown menu again
the frame page will become blank out.
Repro files:
Main.htm
<html><frameset cols="150,*"><frame name="contents" src=""><frame name="main" src="WebForm1.aspx"></frameset></html>
WebForm1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="nastyBug.WebForm1" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><body MS_POSITIONING="GridLayout" bgColor="lime"><form id="Form1" method="post" runat="server"><asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 29px; POSITION:
absolute; TOP: 27px" runat="server" Width="122px" AutoPostBack="True"><asp:ListItem Value="one">one</asp:ListItem><asp:ListItem Value="two">two</asp:ListItem><asp:ListItem Value="three">three</asp:ListItem><asp:ListItem Value="four">four</asp:ListItem></asp:DropDownList></form></body></HTML><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
*** Resolution *** Jul 18 2003 12:16PM Amyluu
Cause/Resolution:
This is a bug with Internet explorer 6.0 sp1.
The original bug, it is closed and moved to longhorn and customer accept
workaround
http://bugcheck/default.asp?URL=/Bugs/IEOESE/24828.asp
New bug: windows bug: 743465
http://bugcheck/default.asp?URL=/Bugs/WindowsOSBugs/743465.asp
In the meanwhile, we can workaround the problem by creating a client side onchange
event handler and delay the postback of a second.
A better sample suggest by earlb:
//need this using for the stringbuilder class
using System.Text;
private void Page_Load(object sender, System.EventArgs e)
{
DropDownList1.Attributes.Add("onchange","testdelay();");
Page.RegisterClientScriptBlock("dropdown1",CreateClientFunction(DropDownList1.Unique
ID));
}
private string CreateClientFunction(string str)
{
StringBuilder func = new StringBuilder();
func.Append("<script language=\"jscript\">");
func.Append("function testdelay(){");
func.Append("setTimeout(\"__doPostBack('" + str + "','')\", 1);");
func.Append("}");
func.Append("</script>");
return func.ToString();
}
====================================================================================
===============================================
Another code sample snippet (SRX020516602444) to workaround this problem, this puts
the script function at the before the starting HTML tag:
private void Page_Load(object sender, System.EventArgs e)
{
//create client site onchange event
DropDownList1.Attributes.Add("onchange","testdelay()");
WriteFunction(DropDownList1.UniqueID);
// Put user code to initialize the page here
}
private void WriteFunction(string str)
{
Response.Write("<script
language=\"jscript\">");
Response.Write("function testdelay(){");
Response.Write("setTimeout(\"__doPostBack('" +
str + "','')\", 1);");
Response.Write("}");
Response.Write("</script>");
}
VB.NET code Snippet:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
ListBox1.Attributes.Add("onchange", "testdelay()")
WriteFunction(ListBox1.UniqueID)
End Sub
Private Sub WriteFunction(ByVal str As System.String)
Response.Write("<script language=""jscript"">")
Response.Write("function testdelay()")
Response.Write("{")
Response.Write("setTimeout(")
Response.Write("""__doPostBack('DropDownList1','')"", 1);")
Response.Write("}")
Response.Write("</script>")
End Sub
Michael Graham, MCSD
Microsoft Developer Support
(980) 776-9966
Click here to reveal e-mail address
Delighting our customers is our top priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please mail us at Click here to reveal e-mail address. You can also contact my manager:
Jeremy Chapman
Middleware Team Manager
Office (469) 775-6360
Email - Click here to reveal e-mail address
Recent viruses on the Internet underscore the threat to all computer users and highlight challenges facing the entire industry in providing security that everyone needs to conduct business. I encourage you to sign up to receive automatic notification of Microsoft Security Bulletins by visiting http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/notify.asp. For more information on security, our Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit http://www.microsoft.com/security. We will be happy to answer any questions or provide assistance with your security needs.
-----------------------------------------------------------------------------------------------------------------------------------------------
(Type your message here)
Thanks Steven,
Your solution worked for me, I had a similar problem with Frames and postback, The page went blank on a Textbox TextChanged event with selection of a dropdown. I added
System.Threading.Thread.Sleep(500);
to the Textbox TextChanged event and it worked!.
Thanks again
--------------------------------
From: Adarsh Nair
以下引自:http://www.dotnet247.com/247reference/msgs/40/204635.aspx,这里向原作者致以敬意。
-----------------------------------------------------------------------------------------------------------------------------------------------
I have an ASP.NET web page -- several auto-post back DropDownLists that perform a query against a relatively large database (3 to 4 seconds delay) that repopulate a couple of datagrids, comboboxes and a chart (using dotnetCharting control) on the same page. This works just fine on its own. However, when I integrated the page into the rest of the site, it is then placed inside a frameset. Again, the page seems to work fine EXCEPT under the following circumstances:
1. Select an item in the DropDownList (the query then starts running on the server)
2. While the query is running, drop the list down again, but DON'T select anything.
3. The query stops running, the code on the server side successfully completes, but the page in the frame does not plot
4. After this point, the page in the frame is 'blown' -- it will not replot again, unless you reload page that creates the frameset.
This is completely repeatable. And it does not have a problem if it is not in a frameset.
I have been coding for a long time, but am new to ASP.NET, so apologies if I have committed some obvious error. Thanks in advance for any ideas.
Bob
-----------------------------------------------------------------------------------------------------------------------------------------------
Hi Bob,
Thanks for posting in the community!
From your description, you encountered a strange problem which occured when
you try edit a dropdownlist after it has just been changed and posted back.
That'll cause the page blown, yes?
If there is anything I misunderstood, please feel free to let me know.
You've tried following the steps you provided and did found this problem.
This seems very strange and currently we're
doing further research on this issue so as to find some proper resource to
assist you. In addtion, here is an approach to workaround this problem if
you feel urgent to get rid of this problem:
We can set a flag when the dropdownlist is first time changed, then if next
time a user try to change it, we'll disable it so as to prevent it from
being droped down again. And here is a sample to show this workaround:
-----------------------aspx page----------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DropDownListError</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5";>
<script language=javascript>
function check()
{
if(document.all("hdFlag").value == "1")
{
document.all("lstMain").disabled = true;
}
}
function setflag()
{
document.all("hdFlag").value = "1";
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label><input
type="hidden" id="hdFlag" runat="server" value="0" NAME="hdFlag"></td>
</tr>
<tr>
<td>
<asp:DropDownList id="lstMain" runat="server" AutoPostBack="True">
<asp:ListItem Value="ItemA" Selected="True">ItemA</asp:ListItem>
<asp:ListItem Value="ItemB">ItemB</asp:ListItem>
<asp:ListItem Value="ItemC">ItemC</asp:ListItem>
<asp:ListItem Value="ItemD">ItemD</asp:ListItem>
</asp:DropDownList>
<select ></select>
</td>
</tr>
</table>
</form>
</body>
</HTML>
-------------------code behind page class-------------------
public class DropDownListError : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList lstMain;
protected System.Web.UI.HtmlControls.HtmlInputHidden hdFlag;
protected System.Web.UI.WebControls.Label lblMessage;
private void Page_Load(object sender, System.EventArgs e)
{
lstMain.Attributes.Add("onchange","setflag();");
lstMain.Attributes.Add("onmousedown","check();");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lstMain.SelectedIndexChanged += new
System.EventHandler(this.lstMain_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void lstMain_SelectedIndexChanged(object sender, System.EventArgs
e)
{
System.Threading.Thread.Sleep(1000*4);
lblMessage.Text = "SelectIndex is changed to " + lstMain.SelectedIndex +
"at " + DateTime.Now.ToLongTimeString();
hdFlag.Value = "0";
}
}
----------------------------------------------
Please try putting the above sample into a frameset to see whether it works
for you. In the meantime, if you have any questions, please feel free to
post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
-----------------------------------------------------------------------------------------------------------------------------------------------
Yes, the page is 'blown' if you just drop-down the list while the previous request is processing-- you do not even have to make another selection. You run the same page, not in a frame, and the problem disappears. I might try the work-around in the short run, but I'd like to figure out what is causing this so I can avoid it in the future. Drop me a private email if you'd like the URL's that generate the problem.
Thanks for any further help.
Bob
-----------------------------------------------------------------------------------------------------------------------------------------------
Hi Bob,
What do you mean exactly when you said the page is "blown"? Can you give
more specific?
thank you,
Amy
This posting is provided "AS IS" with no warranties, and confers no rights.
-----------------------------------------------------------------------------------------------------------------------------------------------
The page comes back completely blank. I used one of my MSDN subscription support calls, and it turns out that this is a known bug with IE, and it is not scheduled to be fixed until the Longhorn release :(
They suggested a similar fix to Alan's, except rather than disabling control, they simply added a delay. I think I like Steve's answer better.
Thanks to everyone for your help.
Bob
-----------------------------------------------------------------------------------------------------------------------------------------------
For the sake of completeness, here is the reply I got from the ASP.NET support folks:
Subject: SRX040209600450
*** Problem Description ***
Customer has an asp.net application with a dropdown menu and enable autopostback in
a frame
When users selects an item, it will do a postback to server. Before the postback
completes and the page refreshes, click the dropdown menu again
the frame page will become blank out.
Repro files:
Main.htm
<html><frameset cols="150,*"><frame name="contents" src=""><frame name="main" src="WebForm1.aspx"></frameset></html>
WebForm1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="nastyBug.WebForm1" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><body MS_POSITIONING="GridLayout" bgColor="lime"><form id="Form1" method="post" runat="server"><asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 29px; POSITION:
absolute; TOP: 27px" runat="server" Width="122px" AutoPostBack="True"><asp:ListItem Value="one">one</asp:ListItem><asp:ListItem Value="two">two</asp:ListItem><asp:ListItem Value="three">three</asp:ListItem><asp:ListItem Value="four">four</asp:ListItem></asp:DropDownList></form></body></HTML><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
*** Resolution *** Jul 18 2003 12:16PM Amyluu
Cause/Resolution:
This is a bug with Internet explorer 6.0 sp1.
The original bug, it is closed and moved to longhorn and customer accept
workaround
http://bugcheck/default.asp?URL=/Bugs/IEOESE/24828.asp
New bug: windows bug: 743465
http://bugcheck/default.asp?URL=/Bugs/WindowsOSBugs/743465.asp
In the meanwhile, we can workaround the problem by creating a client side onchange
event handler and delay the postback of a second.
A better sample suggest by earlb:
//need this using for the stringbuilder class
using System.Text;
private void Page_Load(object sender, System.EventArgs e)
{
DropDownList1.Attributes.Add("onchange","testdelay();");
Page.RegisterClientScriptBlock("dropdown1",CreateClientFunction(DropDownList1.Unique
ID));
}
private string CreateClientFunction(string str)
{
StringBuilder func = new StringBuilder();
func.Append("<script language=\"jscript\">");
func.Append("function testdelay(){");
func.Append("setTimeout(\"__doPostBack('" + str + "','')\", 1);");
func.Append("}");
func.Append("</script>");
return func.ToString();
}
====================================================================================
===============================================
Another code sample snippet (SRX020516602444) to workaround this problem, this puts
the script function at the before the starting HTML tag:
private void Page_Load(object sender, System.EventArgs e)
{
//create client site onchange event
DropDownList1.Attributes.Add("onchange","testdelay()");
WriteFunction(DropDownList1.UniqueID);
// Put user code to initialize the page here
}
private void WriteFunction(string str)
{
Response.Write("<script
language=\"jscript\">");
Response.Write("function testdelay(){");
Response.Write("setTimeout(\"__doPostBack('" +
str + "','')\", 1);");
Response.Write("}");
Response.Write("</script>");
}
VB.NET code Snippet:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
ListBox1.Attributes.Add("onchange", "testdelay()")
WriteFunction(ListBox1.UniqueID)
End Sub
Private Sub WriteFunction(ByVal str As System.String)
Response.Write("<script language=""jscript"">")
Response.Write("function testdelay()")
Response.Write("{")
Response.Write("setTimeout(")
Response.Write("""__doPostBack('DropDownList1','')"", 1);")
Response.Write("}")
Response.Write("</script>")
End Sub
Michael Graham, MCSD
Microsoft Developer Support
(980) 776-9966
Click here to reveal e-mail address
Delighting our customers is our top priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please mail us at Click here to reveal e-mail address. You can also contact my manager:
Jeremy Chapman
Middleware Team Manager
Office (469) 775-6360
Email - Click here to reveal e-mail address
Recent viruses on the Internet underscore the threat to all computer users and highlight challenges facing the entire industry in providing security that everyone needs to conduct business. I encourage you to sign up to receive automatic notification of Microsoft Security Bulletins by visiting http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/notify.asp. For more information on security, our Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit http://www.microsoft.com/security. We will be happy to answer any questions or provide assistance with your security needs.
-----------------------------------------------------------------------------------------------------------------------------------------------
(Type your message here)
Thanks Steven,
Your solution worked for me, I had a similar problem with Frames and postback, The page went blank on a Textbox TextChanged event with selection of a dropdown. I added
System.Threading.Thread.Sleep(500);
to the Textbox TextChanged event and it worked!.
Thanks again
--------------------------------
From: Adarsh Nair
浙公网安备 33010602011771号