Hi, I'm trying to get this drop down list to call a server side method when the selected item is changed. But nothing is happening. (I.e. populateList2 is never called when I select a different item in list1)
<%@ Page Title = "TwoLists" Language="C#" MasterPageFile="MasterPages\\Site.master" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//code to build list 1
}
}
protected void populateList2(object sender, EventArgs e)
{
//code to build list 2 from list 1 selection
Message.Text = "Hello World!"; //THIS NEVER HAPPENS
}
</script>
<asp:Content ID="Content" ContentPlaceHolderID="MainContent" Runat="Server">
<div>
List1: <asp:DropDownList id="list1" runat="server" OnSelectedIndexChanged="populateList2"></asp:DropDownList> <br />
<br />
List2: <asp:DropDownList id="list2" runat="server"></asp:DropDownList>
<asp:Label ID="Message" runat="server"></asp:Label>
</div>
</asp:Content>
Please remember to click “Mark as Answer” on the post that helps you and to unmark it if a marked post does not actually answer your question.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
Marked as answer by Cyberferret on Jul 03, 2012 07:15 PM
Cyberferret
Member
4 Points
4 Posts
Dropdownlist OnSelectedIndexChanged not firing
Jul 03, 2012 06:57 PM|LINK
Hi, I'm trying to get this drop down list to call a server side method when the selected item is changed. But nothing is happening. (I.e. populateList2 is never called when I select a different item in list1)
<%@ Page Title = "TwoLists" Language="C#" MasterPageFile="MasterPages\\Site.master" %> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //code to build list 1 } } protected void populateList2(object sender, EventArgs e) { //code to build list 2 from list 1 selection Message.Text = "Hello World!"; //THIS NEVER HAPPENS } </script> <asp:Content ID="Content" ContentPlaceHolderID="MainContent" Runat="Server"> <div> List1: <asp:DropDownList id="list1" runat="server" OnSelectedIndexChanged="populateList2"></asp:DropDownList> <br /> <br /> List2: <asp:DropDownList id="list2" runat="server"></asp:DropDownList> <asp:Label ID="Message" runat="server"></asp:Label> </div> </asp:Content>thanks!
santa_1975
Star
8574 Points
1499 Posts
Re: Dropdownlist OnSelectedIndexChanged not firing
Jul 03, 2012 06:59 PM|LINK
Hi,
Refer to this link.
http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/c1f66568-1ece-483c-969c-6dc66ea77c49/
Hope this helps.
Thank you!
----------------------
"Microsoft Community Contributor Award 2011"
Specs
Member
618 Points
152 Posts
Re: Dropdownlist OnSelectedIndexChanged not firing
Jul 03, 2012 07:00 PM|LINK
have you tried setting the autopostback="true" in the dropdown list tag?
Nasser Malik
Star
12556 Points
1867 Posts
Re: Dropdownlist OnSelectedIndexChanged not firing
Jul 03, 2012 07:09 PM|LINK
By default postback is false for dropdownlist.
To do post back on selected index change you have to set Autopost true
Just a little modification to your code
Skype: maleknasser1
Cyberferret
Member
4 Points
4 Posts
Re: Dropdownlist OnSelectedIndexChanged not firing
Jul 03, 2012 07:16 PM|LINK
This worked but I needed to use AutoPostBack=true not AutoPostBack="true"
Scratch that lol
thanks!