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
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
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?
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
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
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
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
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.
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
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.