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

Calling a function in RadWindow from parent window

3 Answers 523 Views
Window
This is a migrated thread and some comments may be shown as answers.
Dusty
Top achievements
Rank 1
Dusty asked on 12 May 2010, 05:42 PM
I have a Javascript function that opens a radwindow and then tries to call a function in that window.  It seems liek this should be pretty easy, but I can't get it to call that function.  Here's the calling function:

function openNewWindow(agentID, contractID, company)
            {
                var tabs = tabStrip.get_tabs();
                var tabval = 0;
                var tabFound = false;
                // loop through the tabs looking for existing agent
                for (var i = 0; i < tabs.get_count(); i++) {
                    tabval = tabs.getTab(i).get_value();
                    if (tabval == agentID) {
                        tabFound = true;
                        var oWnd = tabs.getTab(i).correspondingWnd;
                        break;
                    }
                }
                // if agent is already open, alert user and don't open again
                if (tabFound == false) {
                    var oWnd = radopen("AgentWin.aspx?HeaderID=" + agentID, null);
                    oWnd.set_title(agentID);
                    oWnd.maximize();
                    tabStrip.trackChanges();
                    //create a new tab
                    var tab = new Telerik.Web.UI.RadTab();
                    //set the text of the tab
                    tab.set_text(agentID);
                    oWnd.correspondingTab = tab;
                    //add the tab to the tabstrip
                    tabStrip.get_tabs().add(tab);
                    tabStrip.repaint();
                    tab.correspondingWnd = oWnd;
                    tabStrip.commitChanges();
                    //Select this tab
                    tab.select();
                    
                    oWnd.get_contentFrame().contentWindow.CallContractsWindow(agentID, contractID, company);
                }
            }


Since I open the radwindow in this function, I already have have the reference to it (oWnd), so I thought I could just use that last line to call a function in the opened window.  But that last line gives me - "Error: Object doesn't support this property or method"

Can anyone tell me what I'm doing wrong?  Thanks!


3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 13 May 2010, 01:05 PM
Hello Dusty,

The code that you posted seems OK. I would suggest to debug it and to check if oWnd is indeed the RadWindow that you need.
If you still experience problems after that, please open a support ticket and send a small sample project that isolates the problem so I could investigate further.

Thank you in advance for your cooperation.

Sincerely yours,
Georgi Tunev
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.
0
Rick
Top achievements
Rank 1
answered on 30 May 2012, 04:54 PM
Hello I have the same problem.
Do you have an working example using the following scenario.

Main page with a master page and the page within my radwindow has no master page.
Additionally the script manager is on the master page and the radwindow page but not on the main page

Here is the code snipet from the main page:
</telerik:RadTextBox><telerik:RadButton ID="RadButton3" runat="server" 
    Text="Modify Groups" OnClientClicked="showAddUPSSetting"
     AutoPostBack="false">
</telerik:RadButton>

    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Height="600" Width="900" Modal="true" 
                KeepInScreenBounds="true"
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
    <telerik:radcodeblock id="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function showAddUPSSetting() {
            var oWnd = GetRadWindowManager().getWindowByName("RadWindow1");
            oWnd.setUrl("Role_Management_Select.aspx");
            var myData = "some information";
            oWnd.get_contentFrame().contentWindow.setPageTitle(myData);
            oWnd.show();
        }
    </script>
</telerik:radcodeblock>

Here is my code from the radwindow page "Role_Management_Select.aspx"
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
</telerik:RadScriptManager>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">
        function setPageTitle(txt) {
            var oWnd = $find("<%=lblAction.ClientID%>");
            oWnd.value = txt
        }
    </script>
</telerik:RadScriptBlock>

Unfortunately I didn't see any solutoin so far.

Thanks
0
Marin Bratanov
Telerik team
answered on 01 Jun 2012, 02:18 PM
Hello Rick,

Have you examined the following help article on calling functions in windows: http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html? It shows a different way to pass the data that makes sure the page is loaded when you try to call the function. What happens in your case is the following:

1) the RadWindow is not yet opened (i.e. created) and thus the page inside is not even requested from the server at the moment you want to call the function. This will throw a JavaScript error.
2) even if you move the call to show() above your function call the controls on the content page may still not be initialized when the function is called, so you will get an error there, too.
3) it seems you are trying to set the value of a hidden field or textbox in the content page, so you need to use the $get() shortcut, not the $find() shortcut. The former is a shortcut to document.getElementById() which us used for DOM manipulation, while the latter is to findComponent() which is used to access complex ajax-enabled controls (i.e. script controls).

If you do not wish to use the approach that merely passes a value from the article you can use the OnClientPageLoaded event of the RadWindow (e.g. add it dynamically to call the function in it, then in this handler remove it).

An example of the second approach:
function showAddUPSSetting()
{
    var oWnd = GetRadWindowManager().getWindowByName("RadWindow1");
    oWnd.setUrl("Role_Management_Select.aspx");
 
    oWnd.show();
    oWnd.add_pageLoad(callFunction);
}
 
function callFunction(sender, args)
{
    var myData = "some information";
    sender.get_contentFrame().contentWindow.setPageTitle(myData);
    sender.remove_pageLoad(callFunction);
}

content page:
<asp:TextBox ID="lblAction" runat="server" />
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">
        function setPageTitle(txt)
        {
            var oWnd = $get("<%=lblAction.ClientID%>");
            oWnd.value = txt
        
    </script>
</telerik:RadScriptBlock>


Kind regards,
Marin Bratanov
the Telerik team
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 their blog feed now.
Tags
Window
Asked by
Dusty
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Rick
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or