|Number of votes:||5|
Recently I developed a couple of add-ons to an EPiServer project that were using EasySearch for handling search.
These add-ons included two new Gadgets - one for managing search synonyms and one for viewing the search log.
Here are a few useful tips that might come handy when creating EPiServer Gadgets.
Client script, ids and event binding
If you are used to JQuery you normally use static id’s to wire up events and such – typically something similar to this:
Lets say you have 3 radiobuttons inside your gadget, and you want to set up a client side event for the change event.
What the editor sees
The markup inside the view
The rendered html
Since gadgets can have multiple instances present at the same time one cannot use static values for ids. The trick is to use the gadget instance object passed to the init method, and wire up your events inside the "epigadgetloaded” event. You can then use the gadget.element to get hold of the HTML DOM element for the gadget in question.
Use the [ScriptResource] attribute in combination with a ClientScriptInitMethod in the [Gadget] attribute to reference a script to be added to the dashboard and a method in this script to call for each gadget on a tab.
Note the use of html helper LabeledRadioButton to ensure input controls with corresponding labels.
Making a gadget means sharing a common workspace with others. Take a moment to review this list before publishing your gadget to a wider audience: