Wednesday, March 21, 2012

DropDownList event handler serevr side not called

Hello,

this is driving me crazy, below code does a post back to the server but DropDownList1_SelectedIndexChanged1 is never called on the server !
All other buttons work just fine !
If I remove the drop down list from the trigger, than it is called. What is going on here ?

<asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged1"
width="170px"></asp:dropdownlist>
<asp:updatepanel runat="server" id="upAvailability" updatemode="Conditional">
<ContentTemplate>
<asp:Label id="lbSearchResults" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btSearch"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="btNavigateHotels"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:updatepanel>

Hi

I recreated your page and linked up some events and it works fine. Here is what I ended up with, if you want to compare to yours.

HTML

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1" Width="170px">
<asp:ListItem Value="1" Text="option 1"></asp:ListItem>
<asp:ListItem Value="2" Text="option 2"></asp:ListItem>
<asp:ListItem Value="3" Text="option 3"></asp:ListItem>
</asp:DropDownList>
<asp:UpdatePanel runat="server" ID="upAvailability" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lbSearchResults" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btSearch" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="btNavigateHotels" EventName="Click"></asp:AsyncPostBackTrigger>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged">
</asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
<asp:Button runat="server" ID="btSearch" Text="search" OnClick="btSearch_Click" />
<asp:Button runat="server" ID="btNavigateHotels" Text="navigate hotels" OnClick="btNavigateHotels_Click" />
</form>

Codebehind

protected void Page_Load(object sender, EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
lbSearchResults.Text = DropDownList1.SelectedItem.Text;
}
protected void btSearch_Click(object sender, EventArgs e)
{
lbSearchResults.Text = "Search";
}
protected void btNavigateHotels_Click(object sender, EventArgs e)
{
lbSearchResults.Text = "Navigate Hotels";
}

All the events fire correctly. When I attached to the aspnet_wp I could step through the events, and the label control reflected the text I wrote into it.

I even tried calling DataBind() on the DropDownList to see if that killed the event, but it still worked.

I bet thats even more frustrating? :)

Could you post more of your code/page so i can replicate exactly what you have?

Thanks

PaulTAG


Paul.

thanks for your great help on this. I worked around the problem by calling the event handler myself via checking the __EVENTTARGET of the form.

It is very weird because if I add another drop down list this one gets called ! Looking into the Forms collection on the server I cant find the method names there, also not for the buttons which do work (meaning I do not find any Button1_Click in any form value). How does this work, how does ASP know what method to call on the server ? I could than see why this is not happening in my case

Thanks

Joe

No comments:

Post a Comment