Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - Update panel in Master page, refresh button in Content Page

I have Update panel in Master page:

<asp:ScriptManager id="CartScript" runat="server"></asp:ScriptManager>       
<asp:UpdatePanel id="CartBox" runat="server" updateMode="Conditional">
  <ContentTemplate>
    Košík [ <asp:HyperLink NavigateUrl="~/Account/Login.aspx" ID="ShoppingCart" runat="server" text="" /> ] <asp:LinkButton ID="DeleteCart" runat="server" Text="Vymazat košík" OnClick="ThrowCart_Click" />
  </ContentTemplate>
</asp:UpdatePanel>

and Buy Button in Content page:

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">    
  <asp:Button ID="BuyButton" Runat="server" Text="Přidat do košíku" onclick="Buy_Click" />
</asp:Content>

So I need add to Update panel AsyncPostBackTrigger for this button.

First i tryed add it from content page:

protected void Page_Load(object sender, EventArgs e)  
{  
    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();         
    trigger.ControlID = "BuyButton";  
    UpdatePanel panel = (UpdatePanel)Master.FindControl("CartBox");   
    if (panel != null)  
    {  
        panel.Triggers.Add(trigger);  
    }  
    ScriptManager script = (ScriptManager)Master.FindControl("CartScript");  
    script.RegisterAsyncPostBackControl(BuyButton);  
}

But it did error: A control with ID 'BuyButton' could not be found for the trigger in UpdatePanel 'CartBox'.

So i tried it add from Master page:

protected void Page_Load(object sender, EventArgs e)
{                
    if ((Button)MainContent.FindControl("BuyButton")!=null)
    {
        AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
        trigger.ControlID = ((Button)MainContent.FindControl("BuyButton")).ID;
        CartBox.Triggers.Add(trigger);
        CartScript.RegisterAsyncPostBackControl((Button)MainContent.FindControl("BuyButton"));
    }
}

But i got same error. :-(

So can u tell me how I can add to my Update Panel that Button from Content Page can refresh it?

like image 375
John Avatar asked Feb 26 '11 14:02

John


1 Answers

Edit

Place the BuyButton button inside of its own UpdatePanel as well on the content page. Add your AsyncPostBackTrigger to that new UpdatePanel, and then it will be able to find the button, and will use the ScriptManager from the master page.

like image 146
mellamokb Avatar answered Nov 15 '22 19:11

mellamokb