ASP.NET如何获得这个jQuery的跨页面加载/后背上坚持工作? [英] ASP.NET How do I get this jQuery to work persistently across page loads / post backs?

查看:154
本文介绍了ASP.NET如何获得这个jQuery的跨页面加载/后背上坚持工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET我试图用mColorPicker(http://blog.meta100.com/post/600571131/mcolorpicker)与页面我有。

In ASP.NET I'm trying to use mColorPicker (http://blog.meta100.com/post/600571131/mcolorpicker) with a page I have.

它可以在初始页面加载,可以挑选颜色很好,我把它迷上了我多么希望。然而,当我更新页面(点击一个按钮,显示另一个面板/隐藏其他的),它突然停止工作,就好像在JavaScript是不存在的。

It works on initial page load, can pick the colors fine and I have it hooked up how I want. However, when I update the page (click a button to display another panel / hide other ones), it suddenly stops working as if the javascript isn't there.

我有这个code:

<script type="text/javascript">
  $(document).ready(function () {
    $('#color3').bind('colorpicked', function () {
      $(".P_FrameDisplay_222").css("background-color", $(this).val());
    });
  });
</script>
...
<div style="margin: 5px; float: left;">
  <input type="color" id="color3" value="#ff0667" data-text="hidden" style="width: 40px; height: 40px; border-style: none;" />
</div>

我已经与以前不同的JavaScript code这个问题,并修复它,我用这个页面加载javascript函数。

I've had this problem before with different javascript code, and to fix it I use this pageload javascript function.

<script type="text/javascript">
  function pageLoad() {
    imagePreview();
  }
</script>

我如何能得到这个跨页面加载/后背上坚持工作?

How can I get this to work persistently across page loads / post backs?

推荐答案

我假设你使用的UpdatePanel,在这种情况下,你可以使用页面请求管理器,其管理的部分页面更新。像这样的:

I am assuming that you use updatepanels, in that case you can use the page request manager which manages partial page updates. Like this:

//some initialization code

var prm = Sys.WebForms.PageRequestManager.getInstance();

prm.add_endRequest(function (sender, args) {
    //some initialization code
});

这篇关于ASP.NET如何获得这个jQuery的跨页面加载/后背上坚持工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆