开发者

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

开发者 https://www.devze.com 2023-02-13 09:29 出处:网络
I have Update panel in Master page: <asp:ScriptManager id=\"CartScript\" runat=\"server\"></asp:ScriptManager>

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.RegisterAsyncPostBac开发者_JAVA技巧kControl((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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消