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

$find Radwindow returns null

3 Answers 601 Views
Window
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 29 Mar 2016, 01:46 AM

Hi,

I have a page with a couple of RadWindows.

The statement $find("<%=rwPrototypeSummary.ClientID%>") returns null, while similar statement for other RadWindows works fine.

Not sure what am I missing.

The markup is as follows:

<telerik:RadWindowManager ID="Singleton" runat="server" Animation="None" Behaviors="Move"
        Width="900px">
        <windows>
            <telerik:RadWindow ID="rwProtoResponseMediaEdit" Behaviors="Move, Resize, Maximize" Skin="Telerik"
                VisibleStatusbar="false" ReloadOnShow="false" OnClientClose="rwProtoResponseMediaEdit_ClientClose"
                BorderWidth="0" Width="950px" Modal="true" runat="server" Height="530px" Title="Prototype Media"
                NavigateUrl="~/Agency/Authoring/ProtoResponseMediaEdit.aspx">
            </telerik:RadWindow>
            <telerik:RadWindow ID="rwResource" runat="server" Title="Pick a Resource" VisibleStatusbar="false"
                Modal="true" NavigateUrl="~/Agency/Search/ResourceSearch.aspx"
                Width="800" Height="650">
            </telerik:RadWindow>
            <telerik:RadWindow ID="rwPatientProfileEdit" Behaviors="Move, Resize, Maximize" Skin="Telerik"
                VisibleStatusbar="false" ReloadOnShow="false" OnClientClose="rwPatientProfileEdit_ClientClose"
                BorderWidth="0" Width="950px" Modal="true" runat="server" Height="530px" Title="Prototype Patient"
                NavigateUrl="~/Agency/Authoring/PatientProfileEditEdit.aspx">
            </telerik:RadWindow>
            <telerik:RadWindow ID="rwPrototypeMediaEdit" Behaviors="Move, Resize, Maximize" Skin="Telerik"
                VisibleStatusbar="false" ReloadOnShow="false" OnClientClose="rwPrototypeMediaEdit_ClientClose"
                BorderWidth="0" Width="950px" Modal="true" runat="server" Height="530px" Title="Prototype Media"
                NavigateUrl="~/Agency/Authoring/PrototypeMediaEdit.aspx">
            </telerik:RadWindow>
            <telerik:RadWindow ID="rwPrototypeSummary" Behaviors="Move, Resize, Maximize" Skin="Telerik"
                VisibleStatusbar="false" ReloadOnShow="false" OnClientClose="rwPrototypeSummary_ClientClose"
                BorderWidth="0" Width="950px" Modal="true" runat="server" Height="530px" Title="Prototype Summary"
                NavigateUrl="~/Agency/Authoring/PrototypeSummary.aspx">
            </telerik:RadWindow>
        </windows>
    </telerik:RadWindowManager>

 

The Javascript is as follows:

<telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">

        <script type="text/javascript">

     function OpenPrototypeSummary(pid) {
                var url = '<%= ConvertRelativeUrlToAbsoluteUrl("~/Agency/Authoring/PrototypeSummary.aspx") %>';
                url = url + "?id=" + pid;

                console.log(url);

                var oWnd = $find("<%=rwPrototypeSummary.ClientID%>");

                console.log(oWnd);

                oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize);
                //oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize);
                oWnd.show();
                oWnd.setSize(950, 850);
                oWnd.setUrl(url);
                oWnd.minimize();
                oWnd.maximize();
                oWnd.restore();
                oWnd.center();
            }

            function rwPrototypeSummary_ClientClose(sender, args) {

                var arg1 = args.get_argument();

            }
        </script>

    </telerik:RadScriptBlock>

3 Answers, 1 is accepted

Sort by
0
Joseph
Top achievements
Rank 1
answered on 31 Mar 2016, 12:23 AM

I found the problem.

The javascript function OpenPrototypeSummary(pid) is called via Scriptmanager.RegisterStartupScript.

It seems that the function executes before RadWindow rwPrototypeSummary is loaded.

Fixed the problem by modifying OpenPrototypeSummary(pid) to the following:

function OpenPrototypeSummary(pid) {

                var url = '<%= ConvertRelativeUrlToAbsoluteUrl("~/Agency/Authoring/PrototypeSummary.aspx") %>';
                url = url + "?pid=" + pid;

                //logsafe(url);
                setTimeout(function () {

                    var oWnd = $find("<%= rwPrototypeSummary.ClientID %>");
                    logsafe(oWnd);

                    oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize);
                    //oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Resize + Telerik.Web.UI.WindowBehaviors.Maximize);
                    oWnd.show();
                    oWnd.setSize(1024, 850);
                    oWnd.setUrl(url);
                    oWnd.minimize();
                    oWnd.maximize();
                    oWnd.restore();
                    oWnd.center();
                }, 500);
            }

0
Marin Bratanov
Telerik team
answered on 31 Mar 2016, 07:10 AM

Hello Joseph,

A safer approach would be to use the Sys.Application.Load event when you register your script, because this event is provided by the MS AJAX framework precisely so developers can access controls and use scripts safely. You can read more on the subject in the following article: http://docs.telerik.com/devtools/aspnet-ajax/controls/window/troubleshooting/executing-javascript-code-from-server. You can find a simple example that uses this event here: http://docs.telerik.com/devtools/aspnet-ajax/controls/window/troubleshooting/opening-from-the-server.

Regards,

Marin Bratanov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
ozgur
Top achievements
Rank 1
answered on 02 May 2017, 12:25 PM
For me there was another , unrelated javascript error. After I fixed it,  I was able to get the radwindow object.
Tags
Window
Asked by
Joseph
Top achievements
Rank 1
Answers by
Joseph
Top achievements
Rank 1
Marin Bratanov
Telerik team
ozgur
Top achievements
Rank 1
Share this question
or