jQuery插件已加载,但在WebControl中“无法访问" [英] jquery plugin loaded but 'inaccesible' in WebControl

查看:175
本文介绍了jQuery插件已加载,但在WebControl中“无法访问"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在制作fixedTableHeader时遇到麻烦.我找到了一个在简单测试中可以正常工作的jQuery插件.但是我需要将其作为嵌入式资源包含在WebControl中.

I'm having trouble making a fixedTableHeader. I've found a jQuery plugin that works fine in simple test. But I need to include it as an embedded resource in a WebControl.

因此,我已在Assembly.cs中注册了脚本并将其设置为嵌入式资源"

So I'v registered the scripts in the Assembly.cs and set them to be 'embedded resources'

在WebControl中,它们的注册方式如下:

In the WebControl they are registered like this:

 this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "jquery",  Page.ClientScript.GetWebResourceUrl(this.GetType(), "LRGrid.jquery_min.js"));

 var fixedScript = Page.ClientScript.GetWebResourceUrl(this.GetType(), "LRGrid.jquery_fixedheadertable.js");

 this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "fixedheadertable", fixedScript);

 this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "jquery",  Page.ClientScript.GetWebResourceUrl(this.GetType(), "LRGrid.jquery.tablescroll.js"));

然后为了调用我做的脚本:

Then in order to call the script I do:

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SetTable" + ClientID, "; $(document).ready(function(){$('table#" + ClientID + "').fixedHeaderTable({ footer: false, cloneHeadToFoot: false, fixedColumn: false });});", true); 

现在,如果我在FireFox中对其进行测试,我会得到

Now if I test it in FireFox I get

.fixedTableHeader is not a function

IE9告诉我method not supported

我可以使用FireBug或IE Developer工具栏,查看脚本是否已加载?!?!?关于为什么它不可用的任何想法?

I can use FireBug or IE Developer toolbar and see that the script IS loaded?!?!? Any ideas as to why it is not useable??

: 现在,我尝试直接在标记中加载脚本-然后按预期工作.但是,一旦我尝试使用嵌入式资源加载它们,它就会失败,并且不会将fixedTableHeader识别为功能

: Now I've tried to load the scripts directly in the markup - then it works as intended. But as soon as I try to load them using embedded resources it fails and won't recognize fixedTableHeader as a function

$(document).ready(function () { 
    if(jQuery.isFunction($('table#" + ClientID + "').fixedTableHeader)){
      $('table#" + ClientID + "').fixedTableHeader({ height:200, width:'100%' });
    }else{
      alert('unable to load scroll script');
    }
});

推荐答案

好的-因此,该错误位于另一个文件中……Bummer!

Okay - so the error was located in another file... Bummer!

我已经从BasePage加载jQuery(或其他人曾经加载过一次;))

I was already loading jQuery from a BasePage (or someone else did it once ;) )

Page.ClientScript.RegisterClientScriptInclude(
  typeof (WebPageBase), "jQuery", ResolveUrl("~/Scripts/jquery-1.4.1.js"));

当我尝试在此处加载jQuery时,这与我的控件发生了冲突...现在,我不想从任一位置删除jQuery初始化.因此,我决定将BasePage加载设为有条件的.由于BasePage具有LRGrid的知识,但反之则...

This conflicted with my control when I tried to load jQuery there... Now I didn't want to remove jQuery initialization from either location. So I decided to make the BasePage load conditional. Since BasePage has knowledge of LRGrid, but not the other way around...

所以这是解决方法:

if (!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(LRGrid.LRGrid), "jquery"))
      {
        Page.ClientScript.RegisterClientScriptInclude(
             typeof (WebPageBase), "jQuery", ResolveUrl("~/Scripts/jquery-1.4.1.js"));
      }

希望你们中的一些人可以使用它:-p

Hope some of You can use it :-p

这篇关于jQuery插件已加载,但在WebControl中“无法访问"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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