1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / PagesSelector events

PagesSelector events

8 posts, 0 answered
  1. FlR
    FlR avatar
    49 posts
    Registered:
    05 Oct 2010
    07 Jun 2011
    Link to this post
    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!
  2. Ivan Pelovski
    Ivan Pelovski avatar
    43 posts
    Registered:
    24 Sep 2012
    10 Jun 2011
    Link to this post
    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
        }
    }

    I hope this helps.

    Best wishes,
    Ivan Pelovski
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. FlR
    FlR avatar
    49 posts
    Registered:
    05 Oct 2010
    13 Jun 2011
    Link to this post
    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)
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Jun 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. FlR
    FlR avatar
    49 posts
    Registered:
    05 Oct 2010
    15 Jun 2011
    Link to this post
    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?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    20 Jun 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. Saad
    Saad avatar
    98 posts
    Registered:
    10 Oct 2008
    06 Aug 2011
    Link to this post
    Hi Ivan,

    I have made my custom designer successfully. I just wanted to know if I can make pages already selected/checked in PagesSelector?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Aug 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
8 posts, 0 answered