Window onClientClose, Master & Page

6 posts, 0 answers
  1. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 12 May 2009 Link to this post

    Hello.

    I have a masterpage with a RadAjaxManager where I have among other things a virtual scrolling grid like this: http://demos.telerik.com/aspnet-ajax/grid/examples/client/virtualscrollpaging/defaultcs.aspx

    Works perfectly.

    Then I have a content page with a WindowManager. The user can open two windows and add some data. When the windows close, I want to use an ajaxRequest to update the grid. I had this working perfectly before, but once I added the AjaxManager to the masterPage I had to remove it from the content page.

    So I am now trying to contact the master page ajaxManager from the content page on windowClose:
        function ClientClose() { 
            $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("ClientCloseLeagues"); 
        }  

    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As ObjectByVal e As AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest 
        RadAjaxManager1.Alert("AjaxRequest raised from the " + e.Argument) ' works for "LoadMoreRecords" but not "ClientCloseLeagues" 
        If e.Argument = "LoadMoreRecords" Then 
            RadGrid2.PageSize = 15 + RadGrid2.PageSize 
            RadGrid2.Rebind() 
        ElseIf e.Argument = "ClientCloseLeagues" Then 
            Dim RadGrid1 As RadGrid = Me.Page.FindControl("RadGrid1"
            RadGrid1.DataSource = Nothing 
            RadGrid1.Rebind() 
        End If 
    End Sub 

    What actually happens when the ClientClose function gets executed is that RadGrid2 (in the master page) is refreshed, while I am desperately trying to refresh RadGrid1 in the content page.

    I've been reading the documentation: http://www.telerik.com/help/aspnet-ajax/ajxajaxmasterpage.html
    (The link to the code snippet doesn't work: http://www.Telerik.com/asp-net-community/forums/forum-thread.aspx?b311D=ebgbb)

    I'm really unsure what steps I need to take to get this working. The worst thing is I have a deadline today, so pretty please with sugar on top, somebody help me :)

    Regards,
    -DJ-
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 14 May 2009 Link to this post

    Hello Daniel,

    Have in mind that one cannot have two RadAjaxManagers in master and content page at the same time.
    I suggest you placing RadAjaxManager in MasterPage and adding RadAjaxManagerProxy controls in content pages.

    you need the server or client-side RadAjaxManager functionality (like ResponseScripts collection, ajaxRequest function) you can get the "master" manager instance via Server-Side GetCurrent method from the Content Page code-behind:

            RadAjaxManager.GetCurrent(Page)

    Use server-side code block in your JS function to call the master manager AjaxRequest function from the ContentPage as well:

    JavaScript:
     <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
           <script type="text/javascript">  
               function myContentClickHandler()  
               {  
                   $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("content");  
               }  
           </script>  
       </telerik:RadCodeBlock> 

    For more information refer to the following article:
    RadAjax and MasterPage

    Greetings,
    Pavlina
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 14 May 2009 Link to this post

    Hi Pavlina,

    Frankly I am amazed by your reply.

    1. I said: "but once I added the AjaxManager to the masterPage I had to remove it from the content page."
       You say: "Have in mind that one cannot have two RadAjaxManagers in master and content page at the same time."

    2. I explain what I'm trying to do here:
    function ClientClose() {  
            $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("ClientCloseLeagues");  
        }   

    and you reply with:

    function myContentClickHandler()   
               {   
                   $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("content");   
               }   

    3. I say: "I've been reading the documentation: http://www.telerik.com/help/aspnet-ajax/ajxajaxmasterpage.html
    (The link to the code snippet doesn't work: http://www.Telerik.com/asp-net-community/forums/forum-thread.aspx?b311D=ebgbb)"

    you reply with: "For more information refer to the following article:
    RadAjax and MasterPage"

    ==================

    I find it hard to understand how repeating everything I said is supposed to help me in any way. I guess my explanations weren't as clear as I intended them to be.

    As far as using the proxy I don't see how that would help me if it only works in a declarative manner. It was the first thing I tried.

    But I've scrapped this project as we failed to deliver on time, and the deadline was far from negotiable, so please don't spend any more time helping me with this.

    Regards,
    -DJ-



  5. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 15 May 2009 Link to this post

    Hello DJ,

    Straight to your questions:

    • Indeed, if you move the RadAjaxManager to the master page, you should remove it from the content page. Then you could add RadAjaxManagerProxy to the content page. However, note that if you want to update the grid, e.g. Rebind() it in the AjaxRequest event, you need to make sure that you have setting where the RadAjaxManager updates the grid. Such setting could be added programatically in code behind of the content page.
      But if this kind of setup sounds complex to you, you could leave the RadAjaxmanager in the content page.
    • I went through your code and it lloks fine to me. If you can confirm that the code for updating RadGrid1 is executed, then please make sure if the RadAjaxManager updated the RadGrid1 control via ajax.

    Additionally, I suggest that you check out the below demos and articles which elaborate on using RadGrid, RadWindow, RadAjax:

    RadGrid Window editing demo (review the ajax settins there)

    RadAjaxManagerProxy (see how you could handle RadAjaxManager AjaxRequest event in content page, despite the manager is on the master page)
    Adding AjaxSettingsProgramatically (you might need to add dynamic setting in the content page where the manager updates the grid)

    Let me know if this helps and you need further assistance.

    Kind regards,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. -DJ-
    -DJ- avatar
    263 posts
    Member since:
    Oct 2004

    Posted 22 May 2009 Link to this post

    Hi Iana,

    Thanks for your suggestions.
    You should never say never I guess, even though I had to scrap the previous project the same scenario is present in my current one.

    I have to admit I find most of the documentation and demos regarding this confusing.
    I could never see that using arguments in the ajaxRequest call from javascript did anything at all.

    I've ended up using a solution I personally find simpler. At least I got it to work properly.

    I don't use an ajaxproxy, I don't add AjaxSetting programatically and I don't need any javascript code in the page.

    I simply set the onClientClose="ClientClose" in the page (the javascript is unmodified in the masterpage). and then handle it in the AjaxRequest Sub in the master page.
    Protected Sub RadAjaxManager1_AjaxRequest(ByVal s As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) 
        If Session("LoggedIn") = True Then 
            pnlLogin.Visible = False 
            pnlUserOptions.Visible = True 
        End If 
     
     
        Dim url As String = Page.Request.RawUrl.ToLower() 
        If url.EndsWith("mypage.aspx") Then 
     
            Dim RadGrid1 As RadGrid = Me.cphMain.FindControl("RadGrid1") 'cphMain is a contentplaceholder
            RadGrid1.DataSource = Nothing 
            RadGrid1.Rebind() 
     
        End If 
    End Sub 

    You could say the downside of this approach is that I'm checking the session state every time the user updates the grid, but it's not hard to modify the code to skip that if you would want to.

    So my only remaining question would be: Is this approach undesirable for some reason I'm overlooking?

    Regards,
    -DJ-
  7. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 26 May 2009 Link to this post

    Hello -DJ-,

    Thank you for sharing your solution with the community.

    As far as this approach is simpler and easier to understand and work with it, you could go ahead with no worries. The only difference and advantage of the other approach, where the javascript and the AjaxRequest event handler is in the content page, is that all operations concerning the content page are in one place and thus it is more encapsulated.

    Greetings,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017