P
Paul L
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to reproduce the issue on a small test app, the code and html
is below:
Thanks in advance,
Paul
*** Code behind ***
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label output;
protected System.Web.UI.WebControls.DropDownList Dropdownlist1;
protected System.Web.UI.WebControls.DataList DataList1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
ArrayList list = new ArrayList();
list.Add("item1");
list.Add("item2");
list.Add("item3");
DataList1.DataSource = list;
DataList1.DataBind();
}
public void SelectionChanged(object sender, EventArgs e)
{
output.Text = "Changed";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
*** HTML / ASP ***
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TestBed.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</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">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp
ropDownList ID="Dropdownlist1" Runat="server"
EnableViewState="True" AutoPostBack="True"
OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp
ropDownList>
<asp
ataList id="DataList1" style="Z-INDEX: 101; LEFT: 232px; POSITION:
absolute; TOP: 72px"
runat="server">
<ItemTemplate>
<asp
ropDownList ID="dropDown" Runat="server" EnableViewState="True"
AutoPostBack="True" OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp
ropDownList>
</ItemTemplate>
</asp
ataList>
<asp:Label id="output" style="Z-INDEX: 102; LEFT: 472px; POSITION:
absolute; TOP: 88px" runat="server">Label</asp:Label>
</form>
</body>
</HTML>
DropDownList control which is in the ItemTemplate of a DataList.
I have made an exact copy of the DropDownList control, and placed it outside
of the DataList and it fires the event just fine. So it's definitely to do
with it being in a template.
I've managed to reproduce the issue on a small test app, the code and html
is below:
Thanks in advance,
Paul
*** Code behind ***
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label output;
protected System.Web.UI.WebControls.DropDownList Dropdownlist1;
protected System.Web.UI.WebControls.DataList DataList1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
ArrayList list = new ArrayList();
list.Add("item1");
list.Add("item2");
list.Add("item3");
DataList1.DataSource = list;
DataList1.DataBind();
}
public void SelectionChanged(object sender, EventArgs e)
{
output.Text = "Changed";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
*** HTML / ASP ***
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TestBed.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</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">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp
EnableViewState="True" AutoPostBack="True"
OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp
<asp
absolute; TOP: 72px"
runat="server">
<ItemTemplate>
<asp
AutoPostBack="True" OnSelectedIndexChanged="SelectionChanged">
<asp:ListItem Selected="True" Value="1">One</asp:ListItem>
<asp:ListItem Selected="False" Value="2">Two</asp:ListItem>
<asp:ListItem Selected="False" Value="3">Three</asp:ListItem>
</asp
</ItemTemplate>
</asp
<asp:Label id="output" style="Z-INDEX: 102; LEFT: 472px; POSITION:
absolute; TOP: 88px" runat="server">Label</asp:Label>
</form>
</body>
</HTML>