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

1

6

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?

Prognosticate answered 26/2, 2011 at 14:49 Comment(0)
S
2

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.

Slav answered 26/2, 2011 at 14:54 Comment(1)
@StackOverflowException: Ah, missed that detail. Thanks :)Slav

© 2022 - 2024 — McMap. All rights reserved.