ASP.NET - 母版页中的更新面板,内容页中的刷新按钮
我在主页中有更新面板:
<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>
在内容页面有购买按钮:
<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>
所以我需要为此按钮添加到更新面板 AsyncPostBackTrigger。
首先,我尝试从内容页面添加它:
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);
}
但它出现错误:在 UpdatePanel 'CartBox' 中找不到触发器的 ID 为 'BuyButton' 的控件。
所以我尝试从母版页添加它:
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"));
}
}
但我遇到了同样的错误。 :-(
那么你能告诉我如何添加到我的更新面板中,内容页面中的按钮可以刷新它吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑
将
BuyButton
按钮放置在内容页面上其自己的UpdatePanel
内。将您的AsyncPostBackTrigger
添加到新的UpdatePanel
,然后它将能够找到该按钮,并使用母版页中的ScriptManager
。Edit
Place the
BuyButton
button inside of its ownUpdatePanel
as well on the content page. Add yourAsyncPostBackTrigger
to that newUpdatePanel
, and then it will be able to find the button, and will use theScriptManager
from the master page.