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

Add RadWindow to RadWindowManager from WebMethod

1 Answer 115 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 04 Mar 2013, 05:14 PM
Hi, all.

I have a RadWindowManager sitting in my default.aspx page ("wndMgrDefault").  I'm trying to add a RadWindow to it from Javascript via a WebMethod (using the OnClientClicked property of a RadButton that's also on the same page), but I can't seen to find the wndMgrDefault control when I'm inside the method itself.

Javascript:
function ViewRating(sender, args) {
    PageMethods.set_path('default.aspx');
    PageMethods.OpenRating();
}


VB:
<System.Web.Services.WebMethod()> _
Public Shared Sub OpenRating()
    Dim currPg As Page = DirectCast(HttpContext.Current.Handler, Page)
    Dim mgr As RadWindowManager = DirectCast(currPg.FindControl("wndMgrDefault"), RadWindowManager)
    Dim wndRatings As New RadWindow
    Dim ht As Integer = CInt(HttpContext.Current.Session("WND_HT").ToString)
    Dim wd As Integer = CInt(HttpContext.Current.Session("WND_WD").ToString)
 
    With wndRatings
        ...
    End With
 
    mgr.Windows.Add(wndRatings)
End Sub

For some reason, the mgr variable is coming back as Nothing. If I make the routine a normal server-side method, I can add the window using "wndMgrDefault.Windows.Add(wndRatings)" with no problem, but I didn't want to re-render the entire page every time someone clicks this button.  Is there anything I'm missing by trying to add a RadWindow to the window manager doing it this way?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 06 Mar 2013, 03:47 PM
Hi Jeff,

Page methods are Shared (or static in C#) so they are not instance-specific for the page's class. This means they cannot access the controls on the page. This is widely discussed in the net, for example here and here.

What you can do is either use a callback, or simply create the RadWindow on the client. A RadWindowManager can create RadWindows only with JavaScript, so you can return the needed data from the page method (e.g. an URL) and use the onSuccess handler to open the RadWindow. See this help article on the ways to do that: http://www.telerik.com/help/aspnet-ajax/window-programming-opening.html.


All the best,
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
Jeff
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or