jjzjj

关于 asp.net:partial postbacks 和 jquery

codeneng 2023-03-28 原文

partial postbacks and jquery

我遇到了一个问题,在部分回发时,我的一些 jquery 已停止工作。我有一个带有两个单选按钮的页面,一个用于显示数据,另一个用于显示图片库。我使用 jquery 来显示和隐藏其中一个。

我还有一个模态弹出扩展器,它位于更新面板内。当我关闭 mpe 并切换回图片库时,一些代码停止工作。基本上它是一个画廊,可以在一定时间间隔内切换图像。还有一些缩略图可以做同样的事情(打开一个间隔)和它的缩略图不起作用。

HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<%@ Register Src="~/User_Controls/modify_image_table.ascx" TagName="IMG" TagPrefix="uc2" %>
<%@ Register Src="~/User_Controls/ImageLoaderUC.ascx" TagName="ImageLoader" TagPrefix="uc8" %>



    <ContentTemplate>

       
            <asp:RadioButtonList ID="selectionby" runat="server" Font-Bold="true" RepeatDirection="Horizontal"
                RepeatColumns="2" CssClass="bodycopy">
                </asp:ListItem>
                </asp:ListItem>
            </asp:RadioButtonList>
       
       
            <uc2:IMG ID="IMG1" cssclass="bodycopy" runat="server" />
       
       
            <uc8:ImageLoader ID="ImageLoader" runat="server" />
       
       
            <ProgressTemplate>
               
               
               
                      Loading...
                    <img align="middle" src="../images/Ajax/loading_1.gif" />
               
            </ProgressTemplate>
        </asp:UpdateProgress>
    </ContentTemplate>
</asp:UpdatePanel>

Javascript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
$(document).ready(function (e) {
    // Execute the slideShow
    slideShow(6000);
    thumbInt(); // Assign int to thumbnail list items
    clearShowClass(); // Prevents multiple li having .show

    function clearShowClass() {
        setTimeout(timedInterval, 1000);
    };

    function timedInterval() {
        $('ul.slideshow li').not('.show').css("opacity", 0);
        clearShowClass();
    }

    $('#footer img').mouseover(

function () {
    $(this).animate({
        opacity: 3.7
    })
});

    $('#footer img').mouseout(
  function () {

      $(this).animate({
          opacity: 0.7
      })
  });

    function thumbInt() {
        for (i = 1; i <= $('ul.slideshow li').length; i++) {
            $('#footer .thumbnail' + i).bind('click', { iteration: i }, function (event) {
                $('ul.slideshow li').removeClass('show').css("opacity", 0).add($('ul.slideshow li:nth-child(' + event.data.iteration + ')').addClass('show').css("opacity", 0.0).animate({
                    opacity: 1.0
                }, 1000));

                $('#footer li').removeClass('highlight').add($('#footer li:nth-child(' + event.data.iteration + ')').addClass('highlight').add($('#footer li:nth-child(' + event.data.iteration + ') img')));

            });
        };
    };
});


function slideShow(speed) {

    //Set the opacity of all images to 0
    $('ul.slideshow li').css({
        opacity: 0.0
    });

    //Get the first image and display it (set it to full opacity)
    $('ul.slideshow li:first').css({
        opacity: 1.0
    }).addClass('show');


    //Get the first thumbnail and change css
    $('#footer li:first').css({
        opacity: 1.0
    }).addClass('highlight');


    //Call the gallery function to run the slideshow
    var timer = setInterval('gallery()', speed);

    //Pause the slideshow on mouse over content
    $('#footer, ul.slideshow').hover(

function () {
    clearInterval(timer);
},

function () {
    timer = setInterval('gallery()', speed);
});
}

function gallery() {
    //if no IMGs have the show class, grab the first image
    var current = ($('ul.slideshow li.show') ? $('ul.slideshow li.show') : $('#ul.slideshow li.first'));

    //Get next image, if it reached the end of the slideshow, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption') ? $('ul.slideshow li:first') : current.next()) : $('ul.slideshow li:first'));


    //Set the fade in effect for the next image, show class has higher z-index
    next.css({
        opacity: 4.0
    }).addClass('show').animate({
        opacity: 4.0
    }, 1000);

    // Hide the current image
    current.animate({
        opacity: 0.0
    }, 1000).removeClass('show');

    //if no thumbnails have the highlight class, grab the first thumbnail
    var currentThumb = ($('#footer li.highlight') ? $('#footer li.highlight') : $('#footer li:first'));

    var nextThumb = ($('#footer li:last').hasClass('highlight')) ? $('#footer li:nth-child(1)') : $('#footer li.highlight').next($('#footer li'));


    nextThumb.addClass('highlight');
    currentThumb.removeClass('highlight');
}

基本上我想知道更新面板会如何影响 $(document).ready?

谢谢

  • @mshsayem 有正确的答案。您应该将您的评论移至回答,以便它可以被接受。


$(document).ready 中的代码不会再次被调用以进行部分回发;如果您需要 $(document).ready 函数中的某些功能,那么我建议将这些代码重构为一个函数(例如 initAll())并在部分回发后,从服务器端(在您的事件处理程序中)使用 ClientScriptManager.RegisterClientScriptBlock 函数调用该功能如:

1
2
3
4
...
// last line in your partial postback handler

ScriptManager.RegisterClientScriptBlock(Upd1,typeof(UpdatePanel),"__updp__","initAll();", true);

  • 我尝试创建一个名为 initAll() 的 javascript 函数,并将我的其他 js 函数放入其范围,并且我还在 PreRender 处理程序中使用了 ScriptManager。但它仍然无法正常工作。只有我的一些 javascript 工作。
  • 它不应该在 PreRender 处理程序中;但是在更新面板内控件的事件处理程序中;此外,在 initAll 内,您应该只放置那些更新/使用更新面板内控件状态的 javascript
  • 好的,我会尝试的。我正在使用用户控件,如果我错了,请纠正我,从用户控件调用父控件不是一个好习惯。用户控件应该独立于其父级。
  • 是的,调用父控件不是一个好习惯。在这种情况下,我的想法是将上述代码package到一个函数中,该函数首先检查请求是否与 ScriptManager.GetCurrent(this).IsInAsyncPostBack 异步,然后注册脚本。每次都从主页的 Page_Load 调用该函数。 (很痛苦,我同意)

有关关于 asp.net:partial postbacks 和 jquery的更多相关文章

  1. ruby-on-rails - Ruby net/ldap 模块中的内存泄漏 - 2

    作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代

  2. ruby - 如何模拟 Net::HTTP::Post? - 2

    是的,我知道最好使用webmock,但我想知道如何在RSpec中模拟此方法:defmethod_to_testurl=URI.parseurireq=Net::HTTP::Post.newurl.pathres=Net::HTTP.start(url.host,url.port)do|http|http.requestreq,foo:1endresend这是RSpec:let(:uri){'http://example.com'}specify'HTTPcall'dohttp=mock:httpNet::HTTP.stub!(:start).and_yieldhttphttp.shou

  3. jquery - 我的 jquery AJAX POST 请求无需发送 Authenticity Token (Rails) - 2

    rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送

  4. ruby - Net::HTTP 获取源代码和状态 - 2

    我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur

  5. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  6. .net - .NET 将如何影响 Python 和 Ruby 应用程序? - 2

    我很好奇.NET将如何影响Python和Ruby应用程序。用IronPython/IronRuby编写的应用程序是否会非常特定于.NET环境,以至于它们实际上将变得特定于平台?如果他们不使用任何.NET功能,那么IronPython/IronRuby相对于非.NET同类产品的优势是什么? 最佳答案 我不能说任何关于IronRuby的东西,但是大多数Python实现(如IronPython、Jython和PyPy)都试图尽可能忠实于CPython实现。不过,IronPython正在迅速成为这方面的佼佼者之一,并且在PlanetPyth

  7. jquery - 如何将 AJAX 变量从 jQuery 传递到他们的 Controller ? - 2

    我有一个电子邮件表格。但是我正在制作一个测试电子邮件表单,用户可以在其中添加一个唯一的电子邮件,并让电子邮件测试将其发送到该特定电子邮件。为了简单起见,我决定让测试电子邮件通过ajax执行,并将整个内容粘贴到另一个电子邮件表单中。我不知道如何将变量从我的HAML发送到我的Controllernew.html.haml-form_tagadmin_email_blast_pathdoSubject%br=text_field_tag'subject',:class=>"mass_email_subject"%brBody%br=text_area_tag'message','',:nam

  8. ruby - 在 ASP 页面上 Mechanize 中断 - 2

    require'mechanize'agent=Mechanize.newlogin=agent.get('http://www.schoolnet.ch/DE/HomeDE.htm')agent.clicklogin.link_withtext:/Login/然后我得到Mechanize::UnsupportedSchemeError。 最佳答案 Mechanize不支持javascript但您可以将搜索字段添加到表单并为其分配搜索词并使用mechanize提交表单form=page.forms.firstform.add_fie

  9. ruby-on-rails - 关于 Ruby 的一般问题 - 2

    我在我的rails应用程序中安装了来自github.com的acts_as_versioned插件,但有一段代码我不完全理解,我希望有人能帮我解决这个问题class_eval我知道block内的方法(或任何它是什么)被定义为类内的实例方法,但我在插件的任何地方都找不到定义为常量的CLASS_METHODS,而且我也不确定是什么here,并且有问题的代码从lib/acts_as_versioned.rb的第199行开始。如果有人愿意告诉我这里的内幕,我将不胜感激。谢谢-C 最佳答案 这是一个异端。http://en.wikipedia

  10. ruby - 如何使用 Ruby HTTP::Net 处理 404 错误? - 2

    我正在尝试解析网页,但有时会收到404错误。这是我用来获取网页的代码:result=Net::HTTP::getURI.parse(URI.escape(url))如何测试result是否为404错误代码? 最佳答案 像这样重写你的代码:uri=URI.parse(url)result=Net::HTTP.start(uri.host,uri.port){|http|http.get(uri.path)}putsresult.codeputsresult.body这将打印状态码和正文。

随机推荐