如何从页面更新控件中的 UpdatePanel?

发布于 2024-07-29 04:21:48 字数 454 浏览 3 评论 0原文

我的页面上有一个模式,也包含用户控件。

单击模式中的“确定”按钮时,我想更新页面上用户控件中包含的 UpdatePanel。

目前,模式上的“确定”按钮执行整页回发,我只想更新面板,但我不确定如何将其添加为触发器,因为它不在 UpdatePanel 的控件中。

谢谢。


我有一个部分答案...我可以通过这样做更新面板一次:

Dim addTrigger As New AsyncPostBackTrigger
addTrigger.ControlID = MyButton.ID
addTrigger.EventName = "Click"
MyUserControl.GetUpdatePanel.Triggers.Add(addTrigger)

这将导致第一次部分回发,但在第一次之后它会导致整个页面重新加载。 有任何想法吗?

I have a modal on a page that also contains a user control.

When clicking the 'OK' button in the modal, I would like to update an UpdatePanel that is contained within the user control on the page.

Currently the 'OK' button on the modal does a full page postback, I'd like to just update the panel, but I'm not sure how to add it as a trigger since it's not in the control the UpdatePanel is.

Thanks.


I have a partial answer... I can update the panel once by doing this:

Dim addTrigger As New AsyncPostBackTrigger
addTrigger.ControlID = MyButton.ID
addTrigger.EventName = "Click"
MyUserControl.GetUpdatePanel.Triggers.Add(addTrigger)

This will cause a partial post-back the first time, but after that first time it causes an entire page reload. Any ideas?

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

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

发布评论

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

评论(5

千秋岁 2024-08-05 04:21:48

您可以显式添加“确定”按钮作为 UpdatePanel 的 AsyncPostBackTrigger。

在 UpdatePanel 的 aspx 标记中:

<asp:UpdatePanel ID="updPanel" runat="server">
    <ContentTemplate>
    ....
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="the control" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

或在代码隐藏中:

protected override void OnInit(EventArgs e)
{
    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
    trigger.ControlID = "the Control";
    trigger.EventName = "Click";

    updPanel.Triggers.Add(trigger);

    base.OnInit(e);       
}

You can explicitly add the OK button as a AsyncPostBackTrigger for the UpdatePanel.

In the aspx markup for the UpdatePanel:

<asp:UpdatePanel ID="updPanel" runat="server">
    <ContentTemplate>
    ....
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="the control" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>

or in the code-behind:

protected override void OnInit(EventArgs e)
{
    AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
    trigger.ControlID = "the Control";
    trigger.EventName = "Click";

    updPanel.Triggers.Add(trigger);

    base.OnInit(e);       
}
独﹏钓一江月 2024-08-05 04:21:48

也许我在这里遗漏了一些微妙之处,但是你不能直接调用 Update() 方法

Maybe I am missing some subtlety here, but can't you just call the Update() method on the Update Panel?

少年亿悲伤 2024-08-05 04:21:48

您可以使用以下模式在 JavaScript 中控制面板回发:

var prm = Sys.WebForms.PageRequestManager.getInstance(); 
prm._panelsToRefreshIDs = UPComments.uniqueID;
prm._doPostBack(eventTarget,eventArgument);
theForm.submit();

You can use the following pattern to control a panel postback in JavaScript:

var prm = Sys.WebForms.PageRequestManager.getInstance(); 
prm._panelsToRefreshIDs = UPComments.uniqueID;
prm._doPostBack(eventTarget,eventArgument);
theForm.submit();
顾冷 2024-08-05 04:21:48

您不能仅从代码隐藏中以编程方式添加 AsyncPostBackTrigger 吗?

喜欢这样

Can't you just add an AsyncPostBackTrigger programmatically from the code-behind?

Like This ?

心安伴我暖 2024-08-05 04:21:48

只需将面板的内容放入更新面板中即可:

您的用户控制在这里。

这也将防止弹出窗口消失,直到您希望它消失。

在后面的代码中,您可以使用 popup.show(0 或 pop.hide() 调用它,并通过添加 gan 事件将它们链接到您的用户控件,并在后面的页面代码中处理它。这样您的用户控件就可以直接弹出要做什么以及何时更新面板,如果您出于某种原因需要更新面板,


我刚刚意识到您想要在控件中创建一个方法。调用更新面板的更新方法,然后从您的页面触发该事件。相反,通过充分利用事件,您可以连接您的应用程序来执行一些非常酷的操作。

just put the contents of the Panel in an update panel sothat you have:

Your user control here.

this will also prevent the popup from disapearing until you want it to.

In your code behind you can then call it with popup.show(0 or pop.hide() and link these to your user control by addin gan event ot it and handling it inyour pages code behind. this way your user control can direct the popup what to do and when. you can even for it to update hte update panel if you needed for some reason.


for the case above tha tI just realized is tha tyou wan to updat ehte panel in the control. Create a method i nthe control that calls the update method o teh update panel an dthen fire that event from your page. It's the same principal in reverse. By utilizing event well you can wire up your application to do some pretty cool stuff.

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