Saturday, March 24, 2012

TabContainer and UpdatePanel

Hi everyone,

I have a problem with TabContainer and UpdatePanel. I have an asp:DropDownList item within a TabContainer and I have an UpdatePanel outside of the TabContainer with a GridView in it.

What I would like to do is to update the GridView when the dropdownlist's selectedindexchanged is fired. But I got the following error saying that the dropdownlist control cannot be found which is not true. Dropdown is within TabContainer. Does anyone have any ideas why this is happening, why UpdatePanel cannot recognize dropdownlist within TabContainer?

A control with ID 'ddl' could not be found for the trigger in UpdatePanel 'UpdatePanel1'

<cc1:TabContainer ID="TabContainer1" runat="server">
<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText = "Meta Data">
<ContentTemplate>
<table>
<tr>
<td>
<asp:DropDownList ID="ddl" runat="server" OnSelectedIndexChanged = "ddlBundles_SelectedIndexChanged" AutoPostBack = "true" >
</asp:DropDownList>
</td>
</tr>
</table>
</ContentTemplate>
</cc1:TabPanel>

</cc1:TabContainer><br />

.............

..............

<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gv" runat="server" BackColor="White" BorderColor="#999999"
.........

</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID = "ddl" EventName = "SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>

Check thisdocumentation on UpdatePanels. Triggers in NamingContainers are not supported. You could workaround it by firing an event on the tab container in your ddl event handler. In the UpdatePanel set the tabpanel as the control trigger and set the eventname to be that specific event.

Thanks for the tip. As you mentioned, since TabContainer is a Naming Container, controls within Naming containers can be accessed using '$' sign. And here is the solution for my problem.

<Triggers>
<asp:AsyncPostBackTriggerControlID = "TabContainer1$TabPanel1$ddl" EventName = "SelectedIndexChanged" />
</Triggers>


Besides, there is another solution which I could call Update method of UpdatePanel within the SelectedIndexChanged event of the DropDownList as below.

protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
{

...........

...........
UpdatePanel1.Update();
}


Hi,

here is a useful solution:

1Protected Sub Page_Init(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Init2Dim apbtAs AsyncPostBackTrigger3For Each apbtIn UpdatePanel1.Triggers4If (LinkButton1.UniqueID.EndsWith(apbt.ControlID))Then5 apbt.ControlID = LinkButton1.UniqueID6End If7 If (LinkButton2.UniqueID.EndsWith(apbt.ControlID))Then8 apbt.ControlID = LinkButton2.UniqueID9End If10 If (LinkButton3.UniqueID.EndsWith(apbt.ControlID))Then11 apbt.ControlID = LinkButton3.UniqueID12End If13 If (DataList1.UniqueID.EndsWith(apbt.ControlID))Then14 apbt.ControlID = DataList1.UniqueID15End If16 Next17 End Sub

Greetings!


Yep, that did it for me! You are a genius. Thanks! Big Smile

No comments:

Post a Comment