Saturday, March 24, 2012

DropDownLists OnSelectedIndexChanged wont fire

Here what I do

<atlas:UpdatePanel ID="mypanel" mode="always" runat="server">
<ContentTemplate>
<asp:DropDownList ID="mylist" runat="server"
DataSource="mydatasource"
DataTextField="mytext"
DataValueField="myvalue"
OnSelectedIndexChanged="mylist_SelectedIndexChanged" />
<asp:Label ID="mylabel" runat="server" />
<asp:TextBox ID="mytextbox" runat="server" />
</ContentTemplate>
<Triggers>
<atlas:ControlEventTrigger controlID="mylist"
event="SelectedIndexChanged" />
</Triggers>
</atlas:UpdatePanel>

the logic is simple, when the selected item inside the DropDownList changed, it will change the value of the textbox. inside mylist_SelectedIndexChanged method in the codebehind file is just simple putting a value using mytextbox.Text = "something";

But unfortunatelly, when I click on the DropDownList, change it's selected item, nothing happend. The value of the textbox also didn't change.

Do I do something wrong here? or miss something? Please advise.


Thanks,

Lok

As far as I can see all you need to do is set theAutoPostBack="true"in the DropDownList. Works just fine for me that way.

Greetz,
Zentral


Hi Zentral,

Thanks for the reply.

But, it's true, that giving AutoPostBack="true" will not makes all the page portion refreshed? not just only the UpdatePanel portion?

Or because of the control inside an UpdatePanel, so all the postback action happened only affected particular UpdatePanel.

Regards,

Lok


Hey Lok,

That's correct, due to the fact that the DropDownList is nested within an UpdatePanel, only the data within the panel will be considered for the postback. In this case you can look at the UpdatePanel as a "page scope limiter". Thus only the content within the UpdatePanel will be re-rendered.

You can test this easily for example by placing a label inside the UpdatePanel and placing a different label outside the UpdatePanel. Place your DropDownList inside the UpdatePanel and set the AutoPostBack="true", implement the server event and within that event set both labels (the one inside the updatepanel and the one outside) to the same value. You will notice that only the label inside the UpdatePanel will have its value updated while the one outside will remain unchanged.

Greetz!
Zentral

No comments:

Post a Comment