如何在回发前淡出一行

发布于 2024-07-07 03:23:21 字数 260 浏览 9 评论 0原文

我有一个在 ASP.Net 的 DataList 中创建的表。 该表具有三个文本字段,然后是一个带有编辑按钮的字段和一个带有删除按钮的字段。 当用户单击删除按钮时,它会发回,删除项目,然后再次绑定 DataList。 DataList 位于 UpdatePanel 中,因此该项目会在半秒或更长时间后平滑消失,但我真正想要的是,一旦按下删除按钮,该行就会滑出(向上),并且然后让它删除回发的项目。

我可以使用 jQuery 使行滑出,但回发会妨碍。 你怎么处理那件事呢?

I have a table that is created in a DataList in ASP.Net. This table has three fields of text, then a field with an edit button, and a field with a delete button. When a person clicks the delete button, it posts back, deletes the items, and then binds the DataList again. The DataList is in an UpdatePanel so the item smoothly disappears after a half of a second or maybe a little more, but what I'd really like is for the row to slide out (up) as soon as they hit the delete button, and then have it delete the item on the post back.

I can make the row slide out with jQuery, but the postback gets in the way. How do you deal with that?

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

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

发布评论

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

评论(4

沦落红尘 2024-07-14 03:23:21

您可以使用asp.net中的页面方法向服务器发送请求,而无需执行回发。 它们使用起来非常简单,当 ajax 调用完成时你可以做任何你喜欢的效果(你会得到一个成功时调用的函数)。

如果你想坚持回发,一个解决方案如下:

<asp:Button id="myButton" OnClientClick="return fadeThenAllowSubmit()" ... />

在js中类似:

var allowSubmit = false;
function fadeThenAllowSubmit() {
    if (allowSubmit) return true
    // do the jquery stuff that will be completed in, let's say, 1000ms
    setTimeout(function() {
        allowSubmit = true
        $("input[id$=myButton]").click()
        allowSubmit = false
    }, 1000)
    return false
}

这有点像黑客,想法是最初取消回发,做一些事情,然后设置一个计时器,在其中启用回发。 这种方法的一个大问题是淡入淡出效果和实际删除是独立的(如果出现错误,您仍然会得到淡入淡出效果)。

You can use page methods in asp.net to send a request to the server without doing a postback. They are very simple to use and you can do whatever effect you like when the ajax call is completed (you get a function called on success).

If you want to stick with the post back one solution is the following:

<asp:Button id="myButton" OnClientClick="return fadeThenAllowSubmit()" ... />

and in js something like:

var allowSubmit = false;
function fadeThenAllowSubmit() {
    if (allowSubmit) return true
    // do the jquery stuff that will be completed in, let's say, 1000ms
    setTimeout(function() {
        allowSubmit = true
        $("input[id$=myButton]").click()
        allowSubmit = false
    }, 1000)
    return false
}

It's a bit of a hack, the idea is to cancel the postback initially, do some stuff then set a timer where the postback will be enabled. The big problem with this approach is that the fade effect and the actual delete are independent (in case of an error you still get the fade effect).

我们只是彼此的过ke 2024-07-14 03:23:21

您是否尝试过查看任何 Ajax 控件工具包项目? 我相信如果您不太熟悉的话,其中有一些控件将与客户端(java)代码一起使用

have you tried looking at any of the Ajax control toolkit items? I believe there are some controls in there that will head with client side (java) code if your not extremely familiar

南城旧梦 2024-07-14 03:23:21

我将使用客户端 Javascript 手动将“不透明度”CSS 属性缩放到零,然后将该元素标记为“display: none”,然后提交回发。

我相信在 Internet Explorer 中,您需要使用“Filter”CSS 属性来执行此操作,因为它不支持不透明度。

您可以编写一个例程来设置这两个属性,并且该例程应该涵盖所有主要浏览器。

I would use client side Javascript to manually scale the "opacity" CSS property down to zero, then mark the element as "display: none" then submit the post-back.

I believe that in Internet Explorer, you need to use the "Filter" CSS property to do this as it does not support opacity.

You could just code up a routine to set both properties and that should cover all the major browsers.

余厌 2024-07-14 03:23:21

注册表单“提交”事件的处理程序。

$("form").submit(function() {

    // if user initiated delete action 
    // do your thing with deleted row (effects, etc.)

    // after you're done with it, submit the form from script
    // (you can queue the submission after the effect)
    // the submission from the script won't trigger this event handler

    return false; // prevent submission
}

防止表单提交对于避免干扰您想要执行的效果是必要的。 完成后,您可以继续提交。

Register the handler for form "submit" event.

$("form").submit(function() {

    // if user initiated delete action 
    // do your thing with deleted row (effects, etc.)

    // after you're done with it, submit the form from script
    // (you can queue the submission after the effect)
    // the submission from the script won't trigger this event handler

    return false; // prevent submission
}

Preventing form submission is necessary to avoid interference with the effects you want to perform. After they are finished, you are free to proceed with submission.

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