Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger an update of the UpdatePanel by a control that is in different ContentPlaceHolder

I have a page with two ContentPlaceHolders. One has a DropDown and another UpdatePanel with content.

How can I trigger update to the UpdatePanel by the DropDown's selectedItemChanged event when they are in different ContentPlaceholders?

The following would not work since UpdatePanel1 doesn't know about DropDown1:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"  ChildrenAsTriggers="true">
    <ContentTemplate>
        Some content that needs to be updated here...
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="DropDown1" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>

One way is to make an ajax page method that would be called by javascript on the page when DropDown's item is selected. Then in code behind, inside that page method, call UpdatePanel1.Update().

Is there an easier alternative?

like image 750
dev.e.loper Avatar asked Jan 06 '09 16:01

dev.e.loper


People also ask

What are the triggers supported by UpdatePanel control?

Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their AutoPostBack property set to true.

How many different types of triggers are there in the UpdatePanel control?

Answer: There are 2 types of triggers.

Which control can you use to update a part of the page?

By using UpdatePanel controls, you can refresh selected parts of the page instead of refreshing the whole page with a postback. This is referred to as performing a partial-page update.

What is postback trigger in UpdatePanel?

AsyncPostBackTrigger - use these triggers to specify a control within or outside of the UpdatePanel that, when clicked, should trigger a partial page postback. PostBackTrigger - use these triggers to have a control within the UpdatePanel cause a full page postback rather than a partial page postback.


2 Answers

From http://msdn.microsoft.com/en-us/library/system.web.ui.asyncpostbacktrigger.aspx

The control that the AsyncPostBackTrigger references must be in the same naming container as the update panel for which it is a trigger. Triggers that are based on controls in other naming containers are not supported.

The workaround is to use the UniqueID of the control that the trigger is referencing. Unfortunately the UniqueID isn't qualified until the control has been added to its parent (and its parent has been added to its parent, all the way up the control tree).

In your code behind, try:

UpdatePanel1.Triggers.Add(new AsyncPostBackTrigger()
{
    ControlID = DropDown1.UniqueID,
    EventName = "SelectedIndexChanged", // this may be optional
});
like image 68
Crescent Fresh Avatar answered Sep 28 '22 05:09

Crescent Fresh


In the code-behind file, you should be able to do:

ScriptManager.RegisterAsyncPostBackControl(dropdown1);
like image 21
Robert C. Barth Avatar answered Sep 28 '22 06:09

Robert C. Barth