Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.