ASP.NET如何获得这个jQuery的跨页面加载/后背上坚持工作?如何获得、加载、页面、工作

2023-09-06 22:59:00 作者:该仅自己可见

在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
});
 
精彩推荐