开发者

Calling jquery plugin from .cs file

开发者 https://www.devze.com 2023-01-18 22:47 出处:网络
I have a custom control which is used on many pages. I am making use of a jQuery plugin shown in the below link.

I have a custom control which is used on many pages. I am making use of a jQuery plugin shown in the below link. Link- http://www.jquery.wisdomplug.com/jquery-plugins/jquery-custom-select-box-plugin/

Problem is this plug开发者_JAVA百科in loads on the pages which take time to load and fails on those which load quickly.I also have multiple instances of this plugin on the same pages. I have tried calling the plugin in two different ways as listed below. But it is making no difference.I am doing everything in .cs file. I don't have aspx or ascx file.

01)

Page.ClientScript.RegisterStartupScript(GetType(), "dropdownchecklistOrg-setup" +   
this.GetHashCode(), string.Format("$(document).ready(function() {{ $('#{0}').custSelectBox();}});", listBox.ClientID), true);

02)

Page.ClientScript.RegisterStartupScript(GetType(), "dropdownchecklistOrg-setup" + this.GetHashCode(), string.Format("$('#{0}').custSelectBox();", listBox.ClientID), true);

I get the below error on the pages which are loaded quickly.

$('#ctl00_FullRegion_MainRegion_EditForm_PredefinedLocations_DropdownCheckList').custSelectBox() is not a function.

Please suggest what can be done to fix this.

Thanks

Edit

This issue was due to different versions of jQuery library being loaded. I had 3 plugins on the same page. 1 plugin was loading jQuery 1.42 version and the other 2 plugins were loading jQuery 1.32 version.If the 1.42 version was loaded at start up the other two plugins would fail to work.


Not sure if this is just a typo, but in your code for 01, it should be

$(document).ready(function() { $('#{0}').custSelectBox(); });

and not

$(document).ready(function() {{ $('#{0}').custSelectBox();}});


This issue was due to different versions of jQuery library being loaded. I had 3 plugins on the same page. 1 plugin was loading jQuery 1.42 version and the other 2 plugins were loading jQuery 1.32 version.If the 1.42 version was loaded at start up the other two plugins would fail to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号