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

Forums / Developing with Sitefinity / ButtonSelector producing varying results

ButtonSelector producing varying results

7 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    29 Oct 2010
    Link to this post
    Hi,

    Im using a button selector to select an image various places throughout my site, like so:

    <sfLib:ButtonSelector ID="ImageSelector" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" associatedcontrols="txtImage" runat="server" ButtonText="Choose an image" />

    Strangely, on one usercontrol it returns the image guid, whereas on another control with seemingly exactly the same syntax, it returns the image path.

    Any ideas?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Oct 2010
    Link to this post
    Hi Alastair,

    When you select an item from Images and Documents module we return the dynamic link. If you choose an item from the file system we return the relative path to this file.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    29 Oct 2010
    Link to this post
    Hi Ivan,

    Thats the strange thing - im selecting an image from the Library, not the file system. Also, I have used this exact same piece of code:

    <sfLib:ButtonSelector ID="ImageSelector" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" associatedcontrols="txtImage" runat="server" ButtonText="Choose an image" />

    In plenty of other places on the website, and it reutrns the dynamic link.

    Any thoughts?

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Oct 2010
    Link to this post
    Hello Alastair,

    I am not able to replicate this issue. If you can provide the steps I will give a try.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    29 Oct 2010
    Link to this post
    I'm really not sure what to show you to demonstrate the problem.

    Below is the user control which i am experiencing the error on:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="contentBlockControlDesigner.ascx.cs" Inherits="lib_controls_services_backend_contentBlockControlDesigner" %>
    <%@ Register TagPrefix="sfLib" Namespace="Telerik.Libraries.WebControls" Assembly="Telerik.Libraries" %>
     
    <style  type="text/css">
     
        .rwTransparentWindow {
            z-index: 150000 !important;
            height: 450px !important;
        }
     
        .rwTransparentWindow>table {
            height: 450px !important;
        }
         
        .radButtonList li input {
            display: inline !important;
        }
         
        .radButtonList li label {
            display: inline !important;
            position: relative !important;
            top: -2px !important;
            left: 5px !important;
        }
     
    </style>
     
    <div class="ctrlProps">
        <div class="ctrlContent">
            <h3>Content Block Designer</h3>
            <p>This dialog is for adding content blocks to the website.</p>
            <p>* denotes a required field</p>
            <asp:Label runat="server" Text="Title: *" AssociatedControlID="txtTitle" Font-Bold="true" />
            <asp:TextBox ID="txtTitle" runat="server" Columns="40" />
            <asp:RequiredFieldValidator ControlToValidate="txtTitle" runat="server" Text="required" Display="Dynamic" />
            <br /><br />
            <asp:Label runat="server" Text="Image file: *" AssociatedControlID="txtImage" Font-Bold="true" />
            <asp:TextBox ID="txtImage" runat="server" Columns="40"></asp:TextBox>
            <span style="margin: 5px 5px auto auto;">
                <sfLib:ButtonSelector ID="ImageSelector" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/ImageDialog.aspx" ItemTemplatePath="~/Sitefinity/Admin/ControlTemplates/News/Dialogs/ButtonSelector.ascx" associatedcontrols="txtImage" runat="server" ButtonText="Choose an image" />
                <asp:RequiredFieldValidator runat="server" ControlToValidate="txtImage" ErrorMessage=" required" Display="Dynamic" />
            </span>
            <br /><br />
            <asp:Label runat="server" Text="Content:" AssociatedControlID="Editor" Font-Bold="true" />
            <telerik:RadEditor
                        id="Editor"
                        runat="server"
                        contentareacssfile="~/Sitefinity/Admin/Themes/Default/AjaxControlsSkins/Sitefinity/EditorContentArea.css"
                        toolsfile="~/lib/xml/BasicRadEditorConfig.xml"
                        skin="WebBlue"
                        newlinebr="False"
                        width="95%"
                        ContentFilters="EncodeScripts,FixUlBoldItalic,FixEnclosingP,IECleanAnchors,MozEmStrong,ConvertFontToSpan,ConvertToXhtml,IndentHTMLContent">
                            <ImageManager ViewPaths="~/Images" UploadPaths="~/Images" DeletePaths="~/Images" />
                            <MediaManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                            <FlashManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                            <DocumentManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                            <CssFiles>
                                <telerik:EditorCssFile Value="~/Sitefinity/Admin/Themes/Default/AjaxControlsSkins/Sitefinity/EditorCssFile.css" />
                                <telerik:EditorCssFile Value="~/lib/css/src/admin-editor.css" />
                            </CssFiles>
            </telerik:RadEditor>
            <asp:RequiredFieldValidator ControlToValidate="Editor" runat="server" Text="required" Display="Dynamic" />
            <script type="text/javascript">
             
                Telerik.Web.UI.Editor.CommandList["LinkManager"] = function(commandName, editor, args)
                {
                   var editorArgs = editor.getSelectedElement();
                   if (!editorArgs.nodeName || typeof(editorArgs.nodeName) == "undefined" || editorArgs.nodeName != "A")
                   {                                                                  
                        var sel = editor.getSelection(); 
                        editorArgs = sel;
                        editorArgs.Html = sel.getHtml();
                        editorArgs.Text = sel.getText();                                   
                   }    
                         
                    
                   var myCallbackFunction = function(sender, args)
                   {
                        if (typeof(editorArgs.nodeName) != "undefined" && editorArgs.nodeName == "A")
                            args.parentNode.replaceChild(editorArgs, args);
                        else
                        {
                            var cloned = args.cloneNode(true);
                            var div = args.ownerDocument.createElement("DIV");
                            div.appendChild(cloned);
                            editorArgs.pasteHtml(div.innerHTML);
                        }
                   }
                   editor.showExternalDialog(
                   '<%= ((Telerik.Cms.Web.CmsPageBase)Page).ResolveCmsUrl("~/Sitefinity/UserControls/Dialogs/LinksDialog.aspx") %>',
                   editorArgs,
                   750,
                   600,
                   myCallbackFunction,
                   null,
                   'ImageLibraryDialog',
                   false,
                   Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                   false,
                   true)
                };
     
                Telerik.Web.UI.Editor.CommandList["SetLinkProperties"] = function(commandName, editor, args)
                {
                   var editorArgs = editor.getSelectedElement();
                   if (!editorArgs.nodeName || typeof(editorArgs.nodeName) == "undefined" || editorArgs.nodeName != "A")
                        editorArgs = editor.getSelection();
                    
                   var myCallbackFunction = function(sender, args)
                   {
                        if (typeof(editorArgs.nodeName) != "undefined" && editorArgs.nodeName == "A")
                            args.parentNode.replaceChild(editorArgs, args);
                        else
                        {
                            var cloned = args.cloneNode(true);
                            var div = args.ownerDocument.createElement("DIV");
                            div.appendChild(cloned);
                            editorArgs.pasteHtml(div.innerHTML);
                        }
                   }
                   editor.showExternalDialog(
                   '<%= ((Telerik.Cms.Web.CmsPageBase)Page).ResolveCmsUrl("~/Sitefinity/UserControls/Dialogs/LinksDialog.aspx") %>',
                   editorArgs,
                   750,
                   600,
                   myCallbackFunction,
                   null,
                   'ImageLibraryDialog',
                   false,
                   Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                   false,
                   true)
                  };
                 
            </script>
            <br />
            <asp:Label runat="server" Text="Page to link:" AssociatedControlID="txtPageUrl" Font-Bold="true" />
            <asp:TextBox ID="txtPageUrl" runat="server" Columns="40"></asp:TextBox>
            <span style="margin: 5px 5px auto auto;">
                <sfLib:ButtonSelector WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/PagesSelector.aspx" AssociatedControls="txtPageUrl" runat="server" ButtonText="Select page"  />
            </span>
            <br /><br />
            <asp:Label runat="server" Text="Link text:" AssociatedControlID="txtPageLinkText" Font-Bold="true" />
            <asp:TextBox ID="txtPageLinkText" runat="server" Columns="40"></asp:TextBox>
            <br /><br />
            <asp:Label runat="server" Text="Show grey box background:" AssociatedControlID="chkShowBackground" Font-Bold="true" />
            <asp:CheckBox ID="chkShowBackground" runat="server" />
            <br /><br />
            <asp:Label runat="server" Text="Show line seperator:" AssociatedControlID="chkDisplaySeperator" Font-Bold="true" />
            <asp:CheckBox ID="chkDisplaySeperator" runat="server" />
        </div>
    </div>

    And this is the code of ButtonSelector.ascx

    <script type="text/javascript">
        var selectedItem = null;
         
        function openDialog(clientId, assignedControlIds) {
            var window = $find(clientId);
            assignedControls = assignedControlIds.split(',');
            window.show();
        }
     
        function OnClientClose(sender, eventArgs) {
            if (sender.argument) {
                var title = '';
                var altText = '';
                var src = '';
                var width;
                var height;
                var unresolved;
     
                if (sender.argument.title)
                    title = sender.argument.title;
                if (sender.argument.altText)
                    altText = sender.argument.altText;
                if (sender.argument.src)
                    src = sender.argument.src;
                if (sender.argument.width && sender.argument.height) {
                    width = sender.argument.width;
                    height = sender.argument.height;
                }
                if (sender.argument.unresolved) {
                    unresolved = sender.argument.unresolved;
                }
                else if (sender.argument.attributes["sfref"] != undefined) {
                    unresolved = sender.argument.attributes["sfref"].value;
                }
     
                selectedItem = new SelectedItem(src, altText, title, width, height, unresolved);
     
                if (typeof (sfUseResolvedUrl) == 'undefined') {
                    sfUseResolvedUrl = true;
                }
     
                for (i = 0; i < assignedControls.length; i++) {
                    if (assignedControls[i] != '') {
                        var element = document.getElementById(assignedControls[i]);
                        if (element.src) {
                            if (!(/selectedImage/.test(element.id)) && !(/uploadedImage/.test(element.id))) {
                                element.src = sender.argument.src;
                            }
                            else {
                                element.src = sender.argument.src + '?width=300&height=300&decreaseOnly=true';
                            }
                        }
                        else if (typeof (element.value) != 'undefined' && element.value != null) {
                            if (!sfUseResolvedUrl && (/selectedValue/.test(element.id))) {
                                element.value = unresolved;
                            }
                            else {
                                element.value = unresolved;
                               }
                        }
                        else if (typeof (element.href) != 'undefined') {
                            element.href = sender.argument.src;
                        }
                        else if (typeof (element.innerHTML) != 'undefined') {
                            element.innerHTML = sender.argument.title;
                        }
                    }
                }
            }
        }
     
        function SelectedItem(src, altText, title, width, height, unresolved) {
            this.src = src;
            this.altText = altText;
            this.title = title;
            this.width = width;
            this.height = height;
            this.unresolved = unresolved;
     
            if (typeof (beforeInsertLink) != 'undefined')
                beforeInsertLink(src, altText, title, width, height);
        
    </script>
     
    <telerik:RadWindow OnClientClose="OnClientClose" VisibleStatusbar="false" Width="750" Height="600" runat="server" id="dialogWindow" Behaviors="close" EnableEmbeddedSkins="False" Skin="Sitefinity"></telerik:RadWindow>
    <asp:HyperLink NavigateUrl="javascript:void(0);" runat="server" ID="selectBtn" Text="<%$Resources:Select %>"></asp:HyperLink>

    It's the strangest thing I have come across.

    Thanks
    higgsy
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Oct 2010
    Link to this post
    Hello Alastair,

    Modify the close argument of the RadWindow control inside ItemSelector.ascx file

    var radWindow = getRadWindow();
    closeArgument.src = closeArgument.unresolved;
    radWindow.argument = closeArgument;
    radWindow.close(closeArgument);
     

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  7. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    29 Oct 2010
    Link to this post
    Ok great - that has worked. It doesnt explain though why it works on part of the website and not another. Any thoughts?

    Thanks
    higgsy
Register for webinar
7 posts, 0 answered