views:

440

answers:

2

I have a user control in a master page with two drop down lists. When the user selects an item out of either ddl, I want to load a specific user control inside an update panel on the content page. I can't figure out how to get the user control to trigger the update panel. Any suggestions are very much appreciated.

Master

    <%@ Register src="toolbar.ascx" tagname="toolbar" tagprefix="uc1" %>
<head id="Head1" runat="server">
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
    </div>
    <uc1:toolbar ID="toolbar1" runat="server" />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </form>
</body>
</html>

User Control

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="toolbar.ascx.cs" Inherits="Blah.toolbar" %>
<asp:DropDownList ID="ddlDesiredPage" runat="server" AutoPostBack="True" 
            EnableViewState="True" 
            onselectedindexchanged="goToSelectedPage">
            <asp:ListItem Value="-">DDL 1</asp:ListItem>
        </asp:DropDownList>
        &nbsp;
<asp:DropDownList ID="ddlDesiredPageSP" runat="server" AutoPostBack="True" 
        EnableViewState="True"
        onselectedindexchanged="goToSelectedPage">
            <asp:ListItem Value="-">DDL 2</asp:ListItem>
</asp:DropDownList>

Content Page

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" onload="UpdatePanel1_Load">
        <ContentTemplate>
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </ContentTemplate>
        <Triggers>
        ?????????????????????????????????
        </Triggers>
    </asp:UpdatePanel>
</asp:Content>
+2  A: 

Hi,

If you want to update the panel via the User Control you've created, you could try setting the UpdatePanel's UpdateMode = Conditional. Then, in your User Control's click event (or whichever event), have something like this:

 UpdatePanel mUpdatePanel = this.Page.Master.FindControl("upContent") as UpdatePanel;  
    if (mUpdatePanel != null)  
    {
        mUpdatePanel.Update();  
    }
    else
    {
         //update panel not found
    }

UPDATE

Since you can't access your triggers declaratively, you could add them from the code-behind. On your content page, add something like this:

 AsyncPostBackTrigger triggerUserControl = new AsyncPostBackTrigger();
                        DropDownList ucDDL = this.Page.Master.FindControl("ddlDesiredPage") as DropDownList;
                        triggerUserControl.ControlID = ucDDL.ID;
                        triggerUserControl.EventName = "Click";

                        UpdatePanel1.Triggers.Add(triggerUserControl);

Do the same for the other DropDownList. I haven't tried this, but it seems reasonable.

keyboardP
Ok I see what your doing and I think it's close to what I need. The layout is switched around though. My user control is on the master page, and my updatepanel is in the web content page.
Jisaak
In that case, in your MasterPage code-behind (For the user control event), you could try:`UpdatePanel mUpdatePanel = ContentPlaceHolder1.FindControl("upContent") as UpdatePanel`
keyboardP
I've updated my answer based on your code.
keyboardP
+1  A: 

Try adding a postback trigger to your UpdatePanel:

<Triggers>
    <asp:PostBackTrigger ControlID="ddl..." />
</Triggers>
Dug
Right, but how do i find the ddl if its in a user control on my master page?
Jisaak