SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have extended the CoreResultsWebPart in order to do some custom processing, but I am now considering breaking out some of the functionality into a new web part. Is it considered bad practice to use Javascript in my new web part to alter HTML elements in the CoreResultsWebPart?

In other words, is it acceptable for a web part to use Javascript to interfere with another web part, or should each web part be entirely self-contained?

share|improve this question
up vote 0 down vote accepted

I don't think there exist any bad or best practices when it comes to this. Normally when it comes to the CoreResultsWebPart, if there's any HTML you want to change or remove you just alter the XSL in it.

If you on the other hand want to add some kind of effects with javascript like a hover, click, whatever - then the unwritten "best practice" is to just insert the javascript in a HTML Form Web Part on the page.

Since you have already extended the web part I don't see why it would be an issue to add a script tag with a javascript file source to the control via the OnInit or OnLoad method.

share|improve this answer
Yes, I'm currently emitting the javascript link in CreateChildControls(), but I'm hoping to have the javascript work with the original CoreResultsWebPart too, so I won't be able to put it in my extended web part. – Ciaran Jun 12 '13 at 11:52
Then I would recommend you put the javascript in a HTML Form Web Part on the page. – Daniel Ziga Jun 12 '13 at 12:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.