Search code examples
c#asp.netupdatepanel

UpdatePanel Questions


I have an update panel that lives in a control that lives on a masterpage. Is it possible to access the updatepanel and cause it to fire in the code-behind of another aspx page that this control is added to at run-time?

There is one case where a button is clicked on page X, and when that button is clicked, I need the update-panel to run. I have tried this so far with no luck:

Code-Behind

udp = FindControl("udpWishlist") as UpdatePanel;
if (udp != null){
    udp.Update();
}

Snippet from control of the UpdatePanel I'm trying to use

<!--update wishlist on cartadd-->
<asp:UpdatePanel ID="udpWishlist" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:LinkButton ID="lbwishlist" runat="server" href="/wishlist.aspx"></asp:LinkButton>
    </ContentTemplate>
    <Triggers>
    </Triggers>
</asp:UpdatePanel>

Solution

  • Well, you can create a public Method inside the user control, like this:

    public void Update()
    {
        udpWishlist.Update();
    }
    

    Inside the page that contains the UserControl:

    YourUserControlType uc = (YourUserControlType)Page.FindControl("YourUserControlID");
    uc.Update();