如何在主页面控件中更新updatePanel?

时间:2011-05-06 13:39:02

标签: asp.net updatepanel web-controls

我有一个Web控件,我在其中放置了一个updatePanel。该控件在主页面中注册。在这个Master的contentPage中我有一个按钮,我希望在Web控件中更新我的更新面板。它似乎很简单......对吧!?但它不会起作用。

这是我的murkup&代码:

母版页:

<%@ 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>

网络控件:

<%@ 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:

%@ 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));
                }

        }

    }
}

我希望网页控件在页面的按钮上以异步方式运行PanUpdateCart_Load()方法。那可能吗?

1 个答案:

答案 0 :(得分:0)

EventName="Clicked" />

我认为必须

EventName="Click" />

但我不确定这是否是造成问题的原因,但您可以查看。