Unable to get radWindow from UserControl (.ascx)

5 posts, 0 answers
  1. Phaneendra
    Phaneendra avatar
    27 posts
    Member since:
    Jul 2011

    Posted 06 Nov 2012 Link to this post

    HI,
    I placed rad window control in asp.net user control page and trying to load a url in that radwindow
    As Technically its difficult to have javascript in user control i placed in a JS file and loaded that file with Master Page load event.
    But Now my problem I'm unable to find the radwindo and also unable to open the url in the window.
    Please help me in this regards. Plz find my code snipplet.
    Below is my Button click event code in Asp.Net User Control

    protected void lnkGenearateFull_Click(object sender, EventArgs e)
           {
               string url = "~/AppUI/Payments/ReportExport.aspx";
               Page pg = (Page)System.Web.HttpContext.Current.Handler;
               ScriptManager.RegisterStartupScript(pg,typeof(Page), "openWindow", "openWindow('" + url + "','"+ radWindow.ClientID +"');", true);
               ScriptManager.RegisterStartupScript(pg, typeof(Page), "CloseWindow", "CloseWindow();", true);
     
           }
    and My below is my JS Code
    function openWindow(url, radwinId) {
        alert(url);
        alert(radwinId);
        var window = $find(radwinId);alert(window);
        window.setUrl(url);
        window.show();
    }
    function CloseWindow() {
        var window = $find('<%= radWindow.ClientID %>');
        if (window != null) {
            window.close();
        }
    }

    Regards
    Phaneendra Varanasi
  2. rdmptn
    rdmptn avatar
    72 posts
    Member since:
    Aug 2011

    Posted 07 Nov 2012 Link to this post

    1. You can't have server code blocks in your external JS files. They have to be parsed by the ASP engine which does not happen with static content like JS files.If the CloseWindow() function should be executed from inside a content page - take a look at the following demo: http://demos.telerik.com/aspnet-ajax/window/examples/contenttemplatevsnavigateurl/defaultcs.aspx. The Dialog1 page show how to close it. If you are using the COntentTemplate - simply store a reference to the opened RadWIndow in a global variable, or in a hidden field, or pass it as a paremeter.

    2. Don't close your RadWindow immedialtely after you open it. The subsequent script registrations do exactly this.

    2. Don't name your variables window, this is a reserved variable that hosts all things in the page
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Phaneendra
    Phaneendra avatar
    27 posts
    Member since:
    Jul 2011

    Posted 08 Nov 2012 Link to this post

    Yes, I too got your point but my concern it that radwindow is existing on page of user control but unable to read it.
    Hope your got it. Below scenario.
    -- In my User control I placed a radwindow loading other page content in that.
    Now, Using javascript I need to invoke the radwindow.

    Regards
    Phaneendra Varanasi
  5. rdmptn
    rdmptn avatar
    72 posts
    Member since:
    Aug 2011

    Posted 09 Nov 2012 Link to this post

    Debug your code and see if there is an error.

    First alert the ClientID of the RadWindow.

    Then, if you are not using AJAX, use the Sys.Application.Load event to execute your script, as you will not have a RadWindow to $find() before that: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx.

    Use unique keys when registering the script.

    Try using simply this.Page instead of casting the handler to a page instance.

    Just debug your code to find the error. I would bet on an incorrect reference some where. Add alert() calls in the JavaScript to pause the execution and see if the RadWindow shows up but some other code closes it immediately.

  6. Phaneendra
    Phaneendra avatar
    27 posts
    Member since:
    Jul 2011

    Posted 09 Nov 2012 Link to this post

    HI, 
    I have kept Alert() for rad window id , i got the client id in alert message but unable to set the url because im getting the control as NULL

    Regards
    Phaneendra Varanasi
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017