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

Window onClientClose, Master & Page

5 Answers 104 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
-DJ-
Top achievements
Rank 1
-DJ- asked on 12 May 2009, 09:44 AM
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-

5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 14 May 2009, 03:39 PM
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.
0
-DJ-
Top achievements
Rank 1
answered on 14 May 2009, 04:07 PM
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-



0
Iana Tsolova
Telerik team
answered on 15 May 2009, 10:54 AM
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.
0
-DJ-
Top achievements
Rank 1
answered on 22 May 2009, 02:39 PM
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-
0
Iana Tsolova
Telerik team
answered on 26 May 2009, 08:33 AM
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.
Tags
Ajax
Asked by
-DJ-
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
-DJ-
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or