PagesSelector events
The PagesSelector control has 2 buttons - Cancel and Done Selecting.
How can I attach 2 custom javascript functions and in the one attached to Done Selecting to get the selected page guid (if internal selection is used) or the external link / name (if From Other site options is used)
Thank you!
Hello FlR,
We are sorry for the delayed answer. When the Cancel and Done selecting buttons are pressed a javascript event is fired. The event name is doneClientSelection and you can subscribe for it with the add_doneClientSelection method of the PagesSelector client object. The handler for this event should have two parameters: selectedPages - an array with the selected pages and isCanceled - a boolean value holding information whether the Cancel button is clicked. When isCanceled is true then selectedPages is null.
You can use the following code snippet:
_pagesSelector.add_doneClientSelection(doneClientSelectionHandler);
function
doneClientSelectionHandler (selectedPages, isCanceled)
if
(isCanceled)
return
;
for
(
var
i = 0, l = selectedPages.length; i < l; i++)
var
page = selectedPages[i];
if
(page.Url)
//the page is external
// you can use page.Url and page page.Title
else
// the page is internal
// you can use page.Id and page page.Title
Hi Ivan,
Thank you! One last question - How do I get the js reference of PageSelector server side control.
For example - if I have this declaration:
<sf:PagesSelector runat="server" ID="pageSelector" AllowExternalPagesSelection="true" AllowMultipleSelection="false">
How do I get in js it's reference (in your sample _pageSelector)
Hi FlR,
You can get the script references by overriding GetScriptDescriptors
public override IEnumerable<System.Web.UI.ScriptDescriptor> GetScriptDescriptors()
var descriptors = new List<ScriptDescriptor>();
var descriptor = (ScriptControlDescriptor)this.GetBaseScriptDescriptors().Last();
descriptors.Add(descriptor);
return descriptors;
internal virtual IEnumerable<ScriptDescriptor> GetBaseScriptDescriptors()
var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
var scriptControlDescriptor = scriptDescriptors.Where(sd => typeof(ScriptControlDescriptor).IsAssignableFrom(sd.GetType())).First() as ScriptControlDescriptor;
scriptControlDescriptor.Type = typeof(HtmlField).FullName;
return scriptDescriptors;
public override IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
var scripts = new List<ScriptReference>(base.GetScriptReferences());
return scripts;
Kind regards,
Ivan Dimitrov
the Telerik team
I want to use this from a user control (System.Web.UI.UserControl) which is in a admin module page; therefore I cannot override those methods - I'm not using it from a designer view.
Is there another way to access it from javascript?
Hi FlR,
These methods are part of IScriptControl interface, so you should be able to use them.
All the best,
Ivan Dimitrov
the Telerik team
Hi Ivan,
I have made my custom designer successfully. I just wanted to know if I can make pages already selected/checked in PagesSelector?
Hi Saad,
You need a function that will select the item again
_pageSelected: function (items)
if (items == null)
return;
var selectedItem = this.get_pageSelector().getSelectedItems()[0];
if (selectedItem)
,
Best wishes,
Ivan Dimitrov
the Telerik team