Tag Archive for jQuery

PeopleEditor in Bound Control

Having problems updating a dynamically created PeopleEditor control on postback when utilising it in a bound repeating control? The following solution might help you.

In the CreateChildControls method of your control create and add a HiddenField control at the same level as the PeopleEditor control you want to update:

peopleEditor = new PeopleEditor();
// Initialise your PeopleEditor
// ...
Controls.Add(peopleEditor);
 
_hiddenField = new HiddenField { ID = "_hiddenField" };
Controls.Add(_hiddenField);

and then in the ItemCommand event (for example) of your bound control, set the value of the HiddenField control to the value of the PeopleEditor:

_hiddenField.Value = peopleEditor.CommaSeparatedAccounts.Replace(",", "; ");

Here we replace the , with a ; as this is the separator used within the page DOM by the people editor.
Read more

Dynamically load JavaScript file

Sometimes you don’t always want a JavaScript file to load. If, for instance, a control that utilises it is loaded by a page that already references the same JavaScript file, you wouldn’t want to load the script file again.

Note: This being a SharePoint blog, the script shown here is tailored for that platform but will quite easily port to other non SharePoint sites.

A good example of this would be a custom SharePoint WebPart that uses jQuery. Now, say you don’t have control over the page that will host the WebPart and therefore can’t guarantee that the jQuery script will be present in the page\master page\delegate header control. You could dynamically load the script file as the WebPart loads. The problem with this is that the rendering page might already be loading the same script.

Also, by loading the jQuery script file, especially in an environment you have little control over (maybe a WebPart you developed, which is used by many different systems and configurations) you could potentially cause a conflict on the use of the $ alias, which jQuery creates by default.
Read more

Follow

Get every new post delivered to your Inbox

Join other followers: