Hello,
On a webpage, create an UpdatePanel with two DropDownLists.
Set AutoPostBack of DropDownList1 to true.
In the SelectedIndexCh anged method, refill DropDownList2 and set the focus
to DropDownList1 using the ScriptManager SetFocus method.
Use the Visual Studio debugger.
Set a breakpoint on in the (!IsPostBack) part of the PageLoad method.
Start the web application and continue after the breakpoint has been reached.
Press once the down-arrow on the DropDownList1.
An update of DropDownList2 will occur as expected.
Press and hold the down-arrow (or up-arrow) so the auto-repeat sets in.
From time to time (not always) the breakpoint gets reached, which is highly
unexpected.
Two questions.
1) Why does this happen?
2) What can I do to prevent this from happening without losing focus and
auto-repeat functionality?
Regards,
Carlo Mekenkamp
default.aspx.cs
---8<---
using System;
using System.Web.UI.W ebControls;
namespace AjaxDdlTest
{
public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.D ataBind(); //breakpoint here
DropDownList1.S electedValue = "0";
DropDownList2.D ataBind();
DropDownList1.F ocus();
}
}
protected void DropDownList1_S electedIndexCha nged(object sender,
EventArgs e)
{
DropDownList ddl = (DropDownList)s ender;
DropDownList2.D ataBind();
ScriptManager1. SetFocus(ddl);
}
protected void DropDownList1_D ataBinding(obje ct sender, EventArgs e)
{
DropDownList ddl = (DropDownList)s ender;
ddl.Items.Clear ();
for (int i = 0; i < 200; i++)
{
ddl.Items.Add(i .ToString());
}
}
protected void DropDownList2_D ataBinding(obje ct sender, EventArgs e)
{
DropDownList ddl = (DropDownList)s ender;
ddl.Items.Clear ();
for (int i = int.Parse(DropD ownList1.Select edValue); i < 200; i++)
{
ddl.Items.Add(i .ToString());
}
}
}
}
---8<---
default.aspx
---8<---
<%@ Page Language="C#" AutoEventWireup ="true" Codebehind="Def ault.aspx.cs"
Inherits="AjaxD dlTest._Default " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptMana ger ID="ScriptManag er1" runat="server" />
<div>
<asp:UpdatePane l ID="UpdatePanel 1" runat="server">
<ContentTemplat e>
<asp:DropDownLi st ID="DropDownLis t1" runat="server"
AutoPostBack="t rue" OnDataBinding=" DropDownList1_D ataBinding"
OnSelectedIndex Changed="DropDo wnList1_Selecte dIndexChanged" />
<br />
<asp:DropDownLi st ID="DropDownLis t2" runat="server"
AutoPostBack="t rue" OnDataBinding=" DropDownList2_D ataBinding" />
</ContentTemplate >
</asp:UpdatePanel >
</div>
</form>
</body>
</html>
---8<---
On a webpage, create an UpdatePanel with two DropDownLists.
Set AutoPostBack of DropDownList1 to true.
In the SelectedIndexCh anged method, refill DropDownList2 and set the focus
to DropDownList1 using the ScriptManager SetFocus method.
Use the Visual Studio debugger.
Set a breakpoint on in the (!IsPostBack) part of the PageLoad method.
Start the web application and continue after the breakpoint has been reached.
Press once the down-arrow on the DropDownList1.
An update of DropDownList2 will occur as expected.
Press and hold the down-arrow (or up-arrow) so the auto-repeat sets in.
From time to time (not always) the breakpoint gets reached, which is highly
unexpected.
Two questions.
1) Why does this happen?
2) What can I do to prevent this from happening without losing focus and
auto-repeat functionality?
Regards,
Carlo Mekenkamp
default.aspx.cs
---8<---
using System;
using System.Web.UI.W ebControls;
namespace AjaxDdlTest
{
public partial class _Default : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.D ataBind(); //breakpoint here
DropDownList1.S electedValue = "0";
DropDownList2.D ataBind();
DropDownList1.F ocus();
}
}
protected void DropDownList1_S electedIndexCha nged(object sender,
EventArgs e)
{
DropDownList ddl = (DropDownList)s ender;
DropDownList2.D ataBind();
ScriptManager1. SetFocus(ddl);
}
protected void DropDownList1_D ataBinding(obje ct sender, EventArgs e)
{
DropDownList ddl = (DropDownList)s ender;
ddl.Items.Clear ();
for (int i = 0; i < 200; i++)
{
ddl.Items.Add(i .ToString());
}
}
protected void DropDownList2_D ataBinding(obje ct sender, EventArgs e)
{
DropDownList ddl = (DropDownList)s ender;
ddl.Items.Clear ();
for (int i = int.Parse(DropD ownList1.Select edValue); i < 200; i++)
{
ddl.Items.Add(i .ToString());
}
}
}
}
---8<---
default.aspx
---8<---
<%@ Page Language="C#" AutoEventWireup ="true" Codebehind="Def ault.aspx.cs"
Inherits="AjaxD dlTest._Default " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptMana ger ID="ScriptManag er1" runat="server" />
<div>
<asp:UpdatePane l ID="UpdatePanel 1" runat="server">
<ContentTemplat e>
<asp:DropDownLi st ID="DropDownLis t1" runat="server"
AutoPostBack="t rue" OnDataBinding=" DropDownList1_D ataBinding"
OnSelectedIndex Changed="DropDo wnList1_Selecte dIndexChanged" />
<br />
<asp:DropDownLi st ID="DropDownLis t2" runat="server"
AutoPostBack="t rue" OnDataBinding=" DropDownList2_D ataBinding" />
</ContentTemplate >
</asp:UpdatePanel >
</div>
</form>
</body>
</html>
---8<---
Comment