This is a migrated thread and some comments may be shown as answers.

getRadWindow().Close(workLink) Firefox OnClick issue

5 Answers 69 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 26 Dec 2013, 09:16 PM
Only in Firefox, using getRadWindow().close(workLink); does not allow a OnClick call from an ASP:LinkButton to fire. There does not seem to be an issue with using a ASP:Button.

If I yank out the following, it fires.
console.log("begin trouble");
            workLink.pages = pageValue; //pages.value <-- just swapped out for pageValue variable;
            selectedText += ")</a>";
            workLink.selectedText = selectedText;
            getRadWindow().close(workLink); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page.  



Here's my code.


 
<asp:LinkButton ID="cmdUpdate" CssClass="dnnPrimaryAction" resourcekey="cmdUpdate" Text="Save and Exit" runat="server" OnClick="cmdUpdate_Click" OnClientClick="if(!insertLinkFromDB()){return false;};" UseSubmitBehavior="false" ></asp:LinkButton
 
 
if (window.attachEvent) {
            window.attachEvent("onload", initDialog);
        }
        else if (window.addEventListener) {
            window.addEventListener("load", initDialog, false);
        }
 
        var pages = document.getElementById("pages");
        var workLink = null;
 
        function getRadWindow() {
            if (window.radWindow) {
                return window.radWindow;
            }
 
            if (window.frameElement && window.frameElement.radWindow) {
                return window.frameElement.radWindow;
            }
 
            return null;
        }
 
        function initDialog() {
            var clientParameters = getRadWindow().ClientParameters; //return the arguments supplied from the parent page  
 
            pages.value = clientParameters.innerHTML;
            workLink = clientParameters;
        }
 
function insertLinkFromDB() //fires when the Insert Link button is clicked on the "New Item" Screen  
        {
            //create an object and set some custom properties to it
            var authorLastValue = $('#referenceAuthor').val();
            var dateValue = $('#referenceYear').val();
            var currentId = $('.highlighted').attr('id');
 
            var selectedText;
 
            selectedText = "<a href=\"#citation_" + currentId + "\">(" + authorLastValue + ", " + dateValue;
 
            var pageValue = $('#pages2').val();
            if (pageValue != "") {
                selectedText += " Pg " + pageValue;
            }
 
            console.log("begin trouble");
            workLink.pages = pageValue; //pages.value <-- just swapped out for pageValue variable;
            selectedText += ")</a>";
            workLink.selectedText = selectedText;
            getRadWindow().close(workLink); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page.  
 
            return true;
        }
 
//This is a radwindow workaround. Buttons call the closewindow function
        function closeWindow() {
            GetRadWindow().close();
        }
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow)
                oWindow = window.radWindow;
            else if (window.frameElement.radWindow)
                oWindow = window.frameElement.radWindow;
            return oWindow;
        }

5 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 27 Dec 2013, 01:06 PM
Hi Mike,

You could use another approach to call Server-side methods. Setting an hidden button in the main ASPX page and attach a JS function to the OnClientClose event of the RadWindow to use the button's API and trigger the post back.

Please examine the following example code:
ASP.NET
<label runat="server" id="Label1"></label>
 
<telerik:RadWindow runat="server" ID="RadWindow1"
    VisibleOnPageLoad="true" NavigateUrl="Default1.aspx"
    OnClientClose="OnClientClose">
</telerik:RadWindow>
 
<telerik:RadButton runat="server" ID="RadButton1"
    OnClick="RadButton1_Click" style="display:none;"></telerik:RadButton>
 
 
<script type="text/javascript">
    function OnClientClose(sender, args) {
        var btn = $find("<%= RadButton1.ClientID %>");
        btn.click();
    }
</script>

C#
protected void RadButton1_Click(object sender, EventArgs e)
{
    Label1.InnerText += "Server-side call ";
}

 

Regards,
Ianko
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Mike
Top achievements
Rank 1
answered on 27 Dec 2013, 03:21 PM
Hi Lanko,
Thanks for getting back to me. I was actually trying to implement this idea yesterday. I'm glad I seem to be on the right track. But alas I have had no luck getting it to work. I will past my code and hopefully you can see the quick fix. The missing info here is I am using DNN and the radwindow is created after I did a custom editor button. So I don't have the radWindow control like you sent.

Here is the js I have in a external js file. I added a call to a function on my .aspx page to fire my dummy button. That call is located in the "myCallBackFunction function.

Now I want to add that I don't like this solution as I want to keep the .js file isolated because this issue is only on this one page and I reuse this js file in many places. so any insight on how to change it on this particular page would be best.

Is there something along the lines of getRadWindow().OnClientClose() that I can implement in the insertLinkFromDB() like there is for getRadWindow().close()?

Thanks for your assistance!!!!
function citationWindow(id)
{
        RadEditorCommandList["References"] = function (commandName, editor, args) {
            // Execute your code here, provide it with any arguments that you need, etc.  
            var elem = editor.getSelectedElement(); //returns the selected element.           
            if (elem.tagName == "A") {
                editor.selectElement(elem);
                argument = elem;
            }
            else {
                //remove links if present from the current selection - because of JS error thrown in IE
                editor.fire("Unlink");
                //remove Unlink command from the undo/redo list
                var commandsManager = editor.get_commandsManager();
                var commandIndex = commandsManager.getCommandsToUndo().length - 1;
                commandsManager.removeCommandAt(commandIndex);
 
                var content = editor.getSelectionHtml();
                var link = editor.get_document().createElement("A");
 
                link.innerHTML = content;
                argument = link;
            }
 
            var myCallbackFunction = function (sender, args) {
                editor.pasteHtml(String.format("{4}", args.pages, args.target, args.className, args.name, args.selectedText))
                clickDummyButton();
            }
            //This currently pulls the file for the diaglog to for the inline citation dialog box.
            //For future enhancement add it to the technologyDetails module as an ASCX
            editor.showExternalDialog(
            '/measurereferenceseditor.aspx?id=' + id,
                argument,
                570,
                600,
                myCallbackFunction,
                null,
                'Insert Measure Reference',
                true,
                Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                false,
                false);
        };
};

Here is the additional code I added to the aspx page

function clickDummyButton() {
            alert("About to click the dum dum");
            document.getElementById("btn_dummy").Click();
        }
 
<asp:Button ID="btn_dummy" runat="server"  OnClick="cmdUpdate_Click" />
0
Mike
Top achievements
Rank 1
answered on 30 Dec 2013, 07:03 PM
Scouring telerik documentation has come up zilch. Can anyone suggest how to access the onClientClose from the getRadWindow function? This function was pulled from the Telerik site to use when adding a custom button to the editor and inserting text into the editor from a radwindwo in DotNetNuke


All relevant code is listed above. If anymore info is needed, I'm happy to share. I need to fix this by 12/31....

And after reading some things and really thinking about it, onClientClose does not seem correct. In a recent post, a Telerik person says "he OnClientClose event is called after the window is closed". Well, the button I want to click was in that window.

But what still perplexes me is why is FF the only one with the issue....



0
Stanimir
Telerik team
answered on 02 Jan 2014, 08:57 AM
Hi Mike,

Check if the following javascript will solve the problem:
function clickDummyButton() {
    alert("About to click the dum dum");
    $telerik("#<%= btn_dummy.ClientID%>").click();
}



Regards,
Stanimir
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Stanimir
Telerik team
answered on 02 Jan 2014, 08:59 AM
Hi,

Actually there is a $ missing the previously provided code. Here is the fixed one:
function clickDummyButton() {
    alert("About to click the dum dum");
    $telerik.$("#<%= btn_dummy.ClientID%>").click();
}


Regards,
Stanimir
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Window
Asked by
Mike
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Mike
Top achievements
Rank 1
Stanimir
Telerik team
Share this question
or