Thursday, April 26, 2012 3:33 PM
I have devleloped a visual webpart (which has Tab interface) used Jquery extensively. The scripts and html are part of user control. When I use this webpart in SP2010 site page, the scripts are not getting executed.
Can I use scripts in usercontrol? Any clues.
Thursday, April 26, 2012 3:36 PM
This link will solve your problem
Let me know if you have any queries :)
"The Only Way To Get Smarter Is By Playing A Smarter Opponent"
Thursday, April 26, 2012 3:43 PM
Thanks I will try implementing this. Will post again if I have any problems.
Thursday, April 26, 2012 3:53 PM
Thanks Ravi, I was just scaned through this artical. My understanding is
I will have to create a user control which will have just scripts and css.
Add this control to master page.
Now use jquery function in my web part. I dont have to add the scripts in my webpart again.
Correct me if I am wrong.
Thursday, April 26, 2012 4:31 PM
can you share any code block or js error msg that will help us to figure out the issue
otherwise jquery works fine with sharepoint as sunch there are no compatibility issues reported.
Thursday, April 26, 2012 4:39 PM
I will try to share the code snipet. I will have to isolate some code so that will be easy to understand.
Thursday, April 26, 2012 8:41 PM
Hi Ishaan here is the sample code. very simple code. I dont know why this is not working.
Friday, April 27, 2012 9:42 AM
In my experience, you may use the user control's id in the jquery, and as in SharePoint, the user control's server id and client id is different, so you may use the server control's id and it is not work, you should use the client id.
And for the handle of the client id, you can refer the below article:
TechNet Community Support
Friday, April 27, 2012 11:18 AM
Jquery is quite interesting with Sharepoint 2010. Thats a correct step to use jquery on user controls.
JQuery can be very well used from User Controls. The necessity to use if from Master Pages or Page Layouts depends on the amount of content that needs the methods in your scripts(JQuery functions).
I have been using Jquery with usercontrols and they as webpart in turn since 2 years. So i can confidently say that your approach correct. Except that, am not sure if you need the Head, HTML, Body tags in your control.
Here is the sample code that am putting below, to make sure your jquery works.
Hope this helps..
Friday, April 27, 2012 1:01 PMThere are several ways to approach this, I solve this by putting the jQuery js file in the site assets library as I describe here: http://sharepointdragons.com/2012/04/18/adding-jquery-to-a-visual-web-part-and-then-implement-parentchild-radio-buttons/
- Proposed As Answer by sharepointworld Friday, April 27, 2012 11:33 PM
Friday, April 27, 2012 2:49 PM
You don't need to put script in the master page unless your actually using it ON the master page. That creates unnecessary load times, it's one more thing that needs to be downloaded and included.
You can create a helper class to regiter jquery as it's needed,
public static ScriptIncludeHelper
public const string jqueryKey = "JQuery1.3.1";
public static RegisterJQueryForPage(Page page, Control control)
page.ClientScript.RegisterClientScriptInclude(control.GetType(), jqueryKey, "/_Layouts/XYZ/JQuery/Jquery-1.3.1.min.js");
Then in your user controls OnInit event, you simple make a call to
Using this model, JQuery will only be put on the page when it's needed, and you can follow this same tactic for other scripts.
For jQuery I actually have a file naming convention, like
etc, Then I modified my RegisterClientScriptInlcude for jquery to always load the highest version, and if I put something like "ScriptDebug=1" in the url query, it loads the debug version.
My Blog: http://www.thesug.org/Blogs/ryan_mann1/default.aspx Website: Under Construction
Monday, April 30, 2012 7:32 PM
hey i think you are facing the issues due to structural issues as
1) in SharePoint it is recommended to use <ScriptLinks> and <CssRegistration> tags instead of <script> <link>
2) you should not include <Html>,<Head> ,<body> and <form> tags in visual webpart as these are already included in the master page
so, try the above code after removing theses tags.
if still face some issue feel free to send me the above code at firstname.lastname@example.org