0

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?

1 Answer 1

0

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.

2
  • 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
    Commented Jun 12, 2013 at 11:52
  • Then I would recommend you put the javascript in a HTML Form Web Part on the page.
    – user2536
    Commented Jun 12, 2013 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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