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

[Solved] RadAjaxManagerProxy Issue

11 Answers 1071 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 02 Apr 2008, 09:32 AM
Hi,

Having got so far with my master page and individual RadAjaxManager controls on my content pages, I am now trying to put in the RadAjaxManagerProxy to tidy up the pages and have come across an issue.

I add the RadAjaxManager to the master page with no settings, but add on the AjaxRequest event handler.  On the individual content pages, I add a RadAjaxManagerProxy.  On the content pages, I need to instantiate client-side ajax requests which will call an AjaxRequest handler on the content page.  With the current solution, the AjaxRequest handler on the master page is called.

How can I achieve this?

Thanks.

11 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 02 Apr 2008, 10:10 AM
Hello Jonathan,

You can achieve that getting the RadAjaxManager control instance through GetCurrent() static method via server-side code block. The code would look like this:

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

This is applicable both for WebUserControls and ContentPages containing RadAjaxManagerProxy control.

Regards,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan
Top achievements
Rank 1
answered on 02 Apr 2008, 10:38 AM
Hi,

Thanks for the reply.

I have already tried this out and this calls the AjaxRequest event handler on the MasterPage. I want it to call an AjaxRequest event handler on the content page.  Is this not possible?
0
Konstantin Petkov
Telerik team
answered on 02 Apr 2008, 11:19 AM
Hello Jonathan,

RadAjaxManagerProxy control is designed completely for design-time purposes so it does not include AjaxRequest either client or server-side events. This is the approach we recommend to follow: put the manager in the master page and get it any time you need to trigger an AJAX request client and server-side.

Regards,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott
Top achievements
Rank 1
answered on 07 Apr 2008, 07:36 PM
I have the same situation.  I don't understand the last reply.  How do you trigger a server side ajax request on a content page?  I want to execute a server-side method, but that method exists on my content page, not on my master page. So I guess the question is, how do I define an AjaxRequest handler for a content page and make that work with the MasterPages' AjaxManager?

Thanks,
Scott

0
Konstantin Petkov
Telerik team
answered on 08 Apr 2008, 07:22 AM
Hello Scott,

You can use some content page's code as follows:

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


I have attached an example for your convenience.

All the best,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Scott
Top achievements
Rank 1
answered on 08 Apr 2008, 01:29 PM
Thank you for your reply.  The problem with this is that the "content" code is on the master page.  I don't want to execute code on a master page.  I want to execute code on a content page.

I have a RadAjaxManagerProxy on my content page, but there is no onAjaxRequest event like there is with the RadAjaxManager.  So if I'm going to have to use the RadAjaxManager, I have no problem referencing that, but I want to execute code on my content pages, not on the master page.

What I'm trying to do is just run some server side code on my content page from a javascript function on my content page.  I thought I was onto something when I saw you can use the onAjaxRequest event.
0
Konstantin Petkov
Telerik team
answered on 08 Apr 2008, 01:59 PM
Hello Scott,

You can achieve that through the other client-side function: ajaxRequestWithTarget. I have updated the page with additional button which executes that. An AJAX setting should be added for the target button as AJAX initiator:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"  %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<script runat="server"
    protected void Button1_Click(object sender, EventArgs e) 
    { 
        Label2.Text = DateTime.Now.ToLongTimeString(); 
    }     
</script> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="Button1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="Label2" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
        <script type="text/javascript"
            function myContentClickHandler() 
            { 
                $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("content"); 
            } 
            function myContentClickTargetHandler() 
            { 
                $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequestWithTarget("<%= Button1.UniqueID %>", ""); 
            } 
        </script> 
    </telerik:RadCodeBlock> 
    <asp:Button ID="Button1" runat="server" OnClientClick="myContentClickHandler(); return false;" Text="content button" OnClick="Button1_Click"/> 
    <asp:Button ID="Button2" runat="server" OnClientClick="myContentClickTargetHandler(); return false;" Text="content button target"/> 
    <asp:Label ID="Label2" runat="server"></asp:Label> 
</asp:Content> 
 

The updated example is attached as well.

Sincerely yours,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stephen
Top achievements
Rank 2
answered on 23 Dec 2008, 01:13 AM

I get the following error message when I try the ajaxRequestWithTarget

 

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

It seems like I'm on the right track but adding this to my webcontrol didn't seem to help.

 

protected

 

override void Render(HtmlTextWriter writer) {

 

Page.ClientScript.RegisterForEventValidation(grdAppointments.UniqueID,

this.ToString());

 

 

base.Render(writer);

 

}

cheers,
Stephen

0
Maria Ilieva
Telerik team
answered on 23 Dec 2008, 11:47 AM
Hi Stephen,

Sometimes ASP.NET throws this exception on fast clicks/post-backs.
Try adding the enableEventValidation property to the Pages element in the web config and setting it to false.
<pages enableEventValidation="false" >

Best wishes,
Maria Ilieva
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
William
Top achievements
Rank 1
answered on 27 Apr 2009, 10:54 AM

Hi Maria

I understand you can author a JavaScript function as below:

            function myContentClickTargetHandler() 

            { 

                $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequestWithTarget("<%= Button1.UniqueID %>", ""); 

            }


to launch an Ajax request to the content page's Button1 control with ajaxRequestWitharget. However, if the control in the content page is a RadGrid, things are not that easy. For example, if we use your RadWindow as the popup window to insert a record for a RadGrid that is placed inside a content page, you would call 
GetRadWindow().BrowserWindow.refreshGrid('navigateToInserted') to refresh the RadGrid in the content page after inserting. Inside refreshGrid function of the content page, you probably need to call something like:

$find("
<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequestWithTarget("<%= RadGrid1.UniqueID >", "navigateToInserted"); 

But what RadGrid event do we need to use to handle this Ajax request, and furthermore, how can we navigate to the inserted record? The challenge here is it is easy for the button control because you can use OnClick to handle Ajax request, secondly, in your demo: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid, there is no content page, so you don’t have this Ajax manager proxy issue.

 

Cheers

 

William

0
Iana Tsolova
Telerik team
answered on 27 Apr 2009, 02:47 PM
Hi William,

In your case I would suggest you not to try postbacking the grid through the RadAjaxManager, but use the grid client-side API to fire grid command. Then you can handle this command in the ItemCommand server event of your grid.

Find more about RadGrid client-side API here.

Check it out and let me know if this works for you and if any issues arise.

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.
Tags
Ajax
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Jonathan
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Stephen
Top achievements
Rank 2
Maria Ilieva
Telerik team
William
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or