问题
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.
So I'v registered the scripts in the Assembly.cs and set them to be 'embedded resources'
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);
Now if I test it in FireFox I get
.fixedTableHeader is not a function
IE9 tells me method not supported
I can use FireBug or IE Developer toolbar and see that the script IS loaded?!?!? Any ideas as to why it is not useable??
EDIT::
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');
}
});
回答1:
Okay - so the error was located in another file... Bummer!
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"));
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...
So here's the solution:
if (!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(LRGrid.LRGrid), "jquery"))
{
Page.ClientScript.RegisterClientScriptInclude(
typeof (WebPageBase), "jQuery", ResolveUrl("~/Scripts/jquery-1.4.1.js"));
}
Hope some of You can use it :-p
来源:https://stackoverflow.com/questions/12602534/jquery-plugin-loaded-but-inaccesible-in-webcontrol