如何更新母版页控件中的 updatePanel?

发布于 2024-11-05 05:13:12 字数 3966 浏览 2 评论 0原文

我有一个 Web 控件,我在其中放置了 updatePanel。该控件注册在母版页中。在这个 Master 的 contentPage 中,我有一个按钮,我想在 Web 控制中更新我的更新面板。好像就这么简单……对吧!?但这是行不通的。

这是我的沉默&代码:

母版页:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteMaster1.master.cs" Inherits="KR.Obsession.UI.Web.Masters.SiteMaster1" %>
<%@ Register Src="~/UserControls/ShoppingCart.ascx" TagName="Cart" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

</head>
<body>
    <form id="form1" runat="server">
        <ajaxToolkit:ToolkitScriptManager EnablePageMethods="true"  runat="server" ID="AjaxScrpMngr1" 
    EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" >

    </ajaxToolkit:ToolkitScriptManager>
                <asp:ContentPlaceHolder ID="content" runat="server">

                </asp:ContentPlaceHolder>
    </form>
</body>
</html>

Web 控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCart.ascx.cs" Inherits="KR.Obsession.UI.Web.UserControls.ShoppingCart" %>

<asp:UpdatePanel runat="server" ID="PanUpdateCart" UpdateMode="Conditional" >
    <ContentTemplate>
        <div class="UserControlCart">
            <div class="CartImage">
                <asp:HyperLink runat="server" ID="LnkCart" ImageUrl="~/Images/Cart.gif" Width="29" Height="27" />
            </div>
            <div class="CartContent">
                <asp:Literal runat="server" ID="LtrCount" Text="У вас: <b>{0}</b> вещиц" />
                <br />
                <asp:Literal runat="server" ID="LtrTotal" Text="на сумму <b>{0}</b>" />
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

和页面:

%@ Page Title="" Language="C#" MasterPageFile="~/Masters/SiteMaster1.Master" AutoEventWireup="true" CodeBehind="ShowItem.aspx.cs" Inherits="KR.Obsession.UI.Web.ShowItem" %>
<%@ MasterType VirtualPath="~/Masters/SiteMaster1.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                    <asp:LinkButton runat="server" ID="LnkBtnAddToCart" CssClass="AddToCart" Text="ДОБАВИТЬ В КОРЗИНКУ" Enabled="false" OnClick="btnAddToCart_Click" />

            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="LnkBtnAddToCart" EventName="Clicked" />
            </Triggers>
        </asp:UpdatePanel>

</asp:Content>

在我的控件后面的代码中,我有:

using System;
using KR.Obsession.UI.Core;

namespace KR.Obsession.UI.Web.UserControls
{
    public partial class ShoppingCart : SharedBaseControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           PanUpdateCart_Load();
        }

        public void PanUpdateCart_Load()
        {

                if (this.Profile.ShoppingCart.Items.Count > 0)
                {
                    LtrCount.Text = string.Format(LtrCount.Text, this.Profile.ShoppingCart.Items.Count.ToString());
                    LtrTotal.Text = string.Format(LtrTotal.Text, UiUtilities.FormatPrice(this.Profile.ShoppingCart.Total));

                }
                else
                {
                    LtrCount.Text = string.Format(LtrCount.Text, 0);
                    LtrTotal.Text = string.Format(LtrTotal.Text, UiUtilities.FormatPrice(0));
                }

        }

    }
}

我希望 Web 控件以异步方式单击页面按钮上的 PanUpdateCart_Load() 方法。这可能吗?

I have a web control, where I put an updatePanel. This control is registered in the master page. In the contentPage from this Master I have a button, that I want to cause an Update of my Update Panel in web control. It seems to be so simple... right!? But it won't work.

Here is my murkup & code:

The Master Page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteMaster1.master.cs" Inherits="KR.Obsession.UI.Web.Masters.SiteMaster1" %>
<%@ Register Src="~/UserControls/ShoppingCart.ascx" TagName="Cart" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

</head>
<body>
    <form id="form1" runat="server">
        <ajaxToolkit:ToolkitScriptManager EnablePageMethods="true"  runat="server" ID="AjaxScrpMngr1" 
    EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" >

    </ajaxToolkit:ToolkitScriptManager>
                <asp:ContentPlaceHolder ID="content" runat="server">

                </asp:ContentPlaceHolder>
    </form>
</body>
</html>

The web control:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ShoppingCart.ascx.cs" Inherits="KR.Obsession.UI.Web.UserControls.ShoppingCart" %>

<asp:UpdatePanel runat="server" ID="PanUpdateCart" UpdateMode="Conditional" >
    <ContentTemplate>
        <div class="UserControlCart">
            <div class="CartImage">
                <asp:HyperLink runat="server" ID="LnkCart" ImageUrl="~/Images/Cart.gif" Width="29" Height="27" />
            </div>
            <div class="CartContent">
                <asp:Literal runat="server" ID="LtrCount" Text="У вас: <b>{0}</b> вещиц" />
                <br />
                <asp:Literal runat="server" ID="LtrTotal" Text="на сумму <b>{0}</b>" />
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

and the Page:

%@ Page Title="" Language="C#" MasterPageFile="~/Masters/SiteMaster1.Master" AutoEventWireup="true" CodeBehind="ShowItem.aspx.cs" Inherits="KR.Obsession.UI.Web.ShowItem" %>
<%@ MasterType VirtualPath="~/Masters/SiteMaster1.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

                    <asp:LinkButton runat="server" ID="LnkBtnAddToCart" CssClass="AddToCart" Text="ДОБАВИТЬ В КОРЗИНКУ" Enabled="false" OnClick="btnAddToCart_Click" />

            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="LnkBtnAddToCart" EventName="Clicked" />
            </Triggers>
        </asp:UpdatePanel>

</asp:Content>

In the code behind of my control I have:

using System;
using KR.Obsession.UI.Core;

namespace KR.Obsession.UI.Web.UserControls
{
    public partial class ShoppingCart : SharedBaseControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           PanUpdateCart_Load();
        }

        public void PanUpdateCart_Load()
        {

                if (this.Profile.ShoppingCart.Items.Count > 0)
                {
                    LtrCount.Text = string.Format(LtrCount.Text, this.Profile.ShoppingCart.Items.Count.ToString());
                    LtrTotal.Text = string.Format(LtrTotal.Text, UiUtilities.FormatPrice(this.Profile.ShoppingCart.Total));

                }
                else
                {
                    LtrCount.Text = string.Format(LtrCount.Text, 0);
                    LtrTotal.Text = string.Format(LtrTotal.Text, UiUtilities.FormatPrice(0));
                }

        }

    }
}

I want the web control run PanUpdateCart_Load() method on Page's button click in async way. Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

公布 2024-11-12 05:13:12
EventName="Clicked" />

我认为必须如此

EventName="Click" />

,但我不确定这是否是导致问题的原因,但您可以检查一下。

EventName="Clicked" />

I think has to be

EventName="Click" />

but I'm not sure if that's what is causing the issue but you can check.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文