Add RadWindow to RadWindowManager from WebMethod

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    17 posts
    Member since:
    Sep 2012

    Posted 04 Mar 2013 Link to this post

    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.

    function ViewRating(sender, args) {

    <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
    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?
  2. Marin Bratanov
    Marin Bratanov avatar
    3908 posts

    Posted 06 Mar 2013 Link to this post

    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:

    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.
Back to Top