简体   繁体   English

ASP.NET jQuery问题

[英]ASP.NET jQuery issue

I'm digging around with jQuery for something work related, and I am trying to get a specific flow of events working which I can't seem to get my head around. 我正在研究与jQuery有关的工作,并且我试图使特定的事件流正常工作,但似乎无法解决。

I understand how jQuery runs on the front end, functions are called or available to call from within the document.ready area, and have got some animation running on my front end upon the page re-loading (after a postback) - how ever, this is not the exact functionality I want. 我了解jQuery如何在前端运行,如何在document.ready区域内调用或可以调用函数,并且在重新加载页面时(在回发之后)在前端运行了一些动画-但是,这不是我想要的确切功能。

Using the standard asp.net postback model (no ajax), is the following possible? 使用标准的asp.net回发模型(无ajax),是否可能进行以下操作?

1) Page loads, some jQuery executes bringing my div's into their correct place via an animation. 1)页面加载,一些jQuery执行通过动画将我的div放到正确的位置。 (Working fine). (工作正常)。 2) User can click on one of the links inside the div (or the div itself) which then executes a jQuery animation effect, once that animation effect is over, use javascript to postback the page passing in the element that was clicked on. 2)用户可以单击div(或div本身)内的链接之一,然后执行jQuery动画效果,一旦动画效果结束,请使用javascript来回发传递被单击元素的页面。 3) Page posts back, I do all my data handling before the page re-loads again and then my document.ready jQuery runs again. 3)页面回发,我会在重新加载页面之前进行所有数据处理,然后再执行document.ready jQuery。

The part I cant seem to get is #2, I can make some jQuery run on the click of my element by attaching a CSS class to the element and then handling the .click event of that class. 我似乎无法获得的部分是#2,通过将CSS类附加到元素上,然后处理该类的.click事件,我可以使jQuery在元素单击时运行。 This work's fine, but the page doesn't post back (the item clicked on is a LinkButton, just for the sake). 这项工作很好,但是页面不会回发(仅出于缘故,单击的项目是LinkBut​​ton)。

If I manually place Postback code inside a JScript function, and call that function at the end of the chain of animation effects within that jQuery function block, the page posts back but I do not get any of the jQuery animation effect. 如果我手动将Postback代码放在JScript函数内,并在该jQuery函数块内的动画效果链的末尾调用该函数,则该页面会回发信息,但我不会得到任何jQuery动画效果。

What i really need to be able to do is 我真正需要做的是

1) Call the jQuery animation effect 2) Wait until that animation effect is complete 3) Perform page postback upon completion 1)调用jQuery动画效果2)等待动画效果完成3)完成后执行页面回发

I'm not a javascript expert by any means, but have managed fine up until this point. 无论如何,我都不是javascript专家,但是到目前为止,一切都很好。

Any points would be greatly appreciated. 任何观点将不胜感激。 Regards 问候

I think the problem you have is because the javascript on the "LinkButton" is being bypassed. 我认为您遇到的问题是因为“ LinkBut​​ton”上的javascript被绕过了。 The javascript is required to make the 'postback' work. 必须使用JavaScript才能执行“回发”。

The simplest solution for this is to change it to a "Button". 最简单的解决方案是将其更改为“按钮”。 IMO the "LinkButton" is bad and should never be used because a) it's not accessible if you don't have javascript b) a user should expect anything that appears to be a link (GET) to be free of side effects. IMO的“ LinkBut​​ton”是不好的,永远不要使用,因为a)如果没有javascript则无法访问b)用户应该期望任何看起来像是链接(GET)的东西都没有副作用。

jQuery animations are asynchronous (so your browser doesn't lock up). jQuery动画是异步的(因此您的浏览器不会锁定)。 If you manually add postback code after your animation call, the postback will likely occur before the animation has a chance. 如果在动画调用之后手动添加回发代码,则回发很可能在动画出现之前发生。

Consider adding your postback code to an animation callback. 考虑将您的回发代码添加到动画回调中。 The callback is called after an animation is complete - which sounds like what you want. 动画完成后将调用回调-听起来像您想要的。

function prePostBackAnimation() {   
    $('something').animate({ width: 70 }, function() {
        //jQuery will call this method after the animation finishes.
        //Add postback code here
        __doPostBack(theTarget,theArgument);
    });
}

Code modified from here . 代码从这里修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM