ASP.NET - UpdatePanel 和 JavaScript

发布于 2024-07-11 20:32:21 字数 280 浏览 4 评论 0原文

有没有办法在 UpdatePanel 进程完成时执行脚本。

我有一个页面允许“插入”、“复制”和“编辑”记录。 这一切都是在 UpdatePanel 上完成的,以防止页面导航。 我想在页面的其他地方打印一条“闪现”消息 - 例如“您已成功输入记录”。 它不在 UpdatePanel 附近,我想对消息使用 jQuery 效果,以便它在 4 秒后淡出。 如何使用 UpdatePanel 发送回脚本或在 UpdatePanel 刷新后执行脚本? 我应该将脚本写入 asp:literal 吗? 想法?

Is there a way to execute script when an UpdatePanel process is finished.

I have a page that allows "inserting", "copying", and "editing" of a record.
This is all done on an UpdatePanel to prevent a page navigation.
Somewhere else on the page I would like to print a "flash" message - like "You have successfully entered a record." It is not near the UpdatePanel and I'd like to use a jQuery effect on the message so it fades out after 4 seconds. How can I send script back with the UpdatePanel or have it execute after a UpdatePanel refresh? Should I write script to an asp:literal? thoughts?

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

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

发布评论

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

评论(6

谈情不如逗狗 2024-07-18 20:32:21

是:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);

然后:

function endRequestHandler(sender, args)
{
  // Do stuff
}

文档此处此处。 请记住,这将针对页面上的每个 AJAX 请求触发。

Yes:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);

And then:

function endRequestHandler(sender, args)
{
  // Do stuff
}

Documentation here and here. Keep in mind that this will fire for every AJAX request on the page.

徒留西风 2024-07-18 20:32:21

这应该可以解决问题:

       <script type="text/javascript">
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_beginRequest(BeginRequestHandler);
            prm.add_endRequest(EndRequestHandler);

            function BeginRequestHandler(sender, args) 
            {
                 //Jquery Call
            }

            function EndRequestHandler(sender, args) 
            {
                 //Jquery Call

            }
        </script> 

This should do the trick:

       <script type="text/javascript">
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_beginRequest(BeginRequestHandler);
            prm.add_endRequest(EndRequestHandler);

            function BeginRequestHandler(sender, args) 
            {
                 //Jquery Call
            }

            function EndRequestHandler(sender, args) 
            {
                 //Jquery Call

            }
        </script> 
摘星┃星的人 2024-07-18 20:32:21

这里有一篇文章介绍了如何使用 ScriptManager 的静态方法 RegisterClientScriptBlock 来完成此操作。 尝试了一下,效果非常好。

http://csharperimage.jeremylikness.com/2009/ 06/注入-dynamic-javascript-into-aspnet.html

Here is an article for how to do it using ScriptManager's static method RegisterClientScriptBlock. Tried it and works like a charm.

http://csharperimage.jeremylikness.com/2009/06/inject-dynamic-javascript-into-aspnet.html

计㈡愣 2024-07-18 20:32:21
var requestManager = Sys.WebForms.PageRequestManager.getInstance();
requestManager.add_beginRequest(function () { alert('here1') });
requestManager.add_endRequest(function () { alert(here2') });

来源:http://www.howtositecore.com/?p=36

var requestManager = Sys.WebForms.PageRequestManager.getInstance();
requestManager.add_beginRequest(function () { alert('here1') });
requestManager.add_endRequest(function () { alert(here2') });

Source: http://www.howtositecore.com/?p=36

雨巷深深 2024-07-18 20:32:21

Sys.WebForms.PageRequestManager.getInstance() 方法也非常适合我。

我处理了很多包含多个更新面板的页面,并且我了解到即使您不希望更新面板刷新,这也会自动触发。 因此,在事件触发的函数内,请确保您有类似的内容:

function BeginRequestHandler(sender, args) {
if (args.get_postBackElement().id == "ID of the Updatepanel") {
// do stuff here

The Sys.WebForms.PageRequestManager.getInstance() method works great for me as well.

I work with a lot of pages that contain multiple Updatepanels and I've learned that this will automatically fire even if the Updatepanel you don't want it for refreshes. So inside the function that fires on the event make sure you have something like:

function BeginRequestHandler(sender, args) {
if (args.get_postBackElement().id == "ID of the Updatepanel") {
// do stuff here
神经暖 2024-07-18 20:32:21

布鲁诺,

首先回答你的直接问题。 在更新面板调用的回调中,您应该能够使用 RegisterStartupScript 调用来调用 JS 方法。 然后在你的 JS 方法中,你将显示该消息,然后你可以使用 do a:

setTimeout('$('#myMessage').fadeOut("slow")', 4000);

让它在 4 秒后消失。

更进一步,由于您已经在实现 JavaScript,我邀请您查看 这篇关于 UpdatePanels 的文章。 如果可能,我会尝试发送 Ajax 调用来进行插入、复制和编辑,这将进一步简化您的用户反馈,并防止线路上出现过多信息。

Bruno,

First, to answer your direct question. In your callback that is being called by the update panel, you should be able to use a RegisterStartupScript call to invoke a JS method . Then in your JS method, you would show the message and then you can use do a:

setTimeout('$('#myMessage').fadeOut("slow")', 4000);

to have it fade away after 4 seconds.

To go one step further, since you're already implementing JavaScript, I would invite you to check out this article about UpdatePanels. If possible, I would try to send Ajax calls to do your inserting, copying, and editing and this would further simplify your user feedback and would prevent excess info across the wire.

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