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

Unable to get radWindow from UserControl (.ascx)

4 Answers 93 Views
Window
This is a migrated thread and some comments may be shown as answers.
Phaneendra
Top achievements
Rank 1
Phaneendra asked on 06 Nov 2012, 08:12 AM
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

4 Answers, 1 is accepted

Sort by
0
rdmptn
Top achievements
Rank 1
answered on 07 Nov 2012, 01:38 PM
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
0
Phaneendra
Top achievements
Rank 1
answered on 08 Nov 2012, 01:08 PM
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
0
rdmptn
Top achievements
Rank 1
answered on 09 Nov 2012, 11:35 AM

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.

0
Phaneendra
Top achievements
Rank 1
answered on 09 Nov 2012, 01:51 PM
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
Tags
Window
Asked by
Phaneendra
Top achievements
Rank 1
Answers by
rdmptn
Top achievements
Rank 1
Phaneendra
Top achievements
Rank 1
Share this question
or