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

Ajaxrequest from javascript, Master page and RadAjaxManagerProxy

2 Answers 101 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
daniel demesmaeker
Top achievements
Rank 1
daniel demesmaeker asked on 10 Sep 2012, 07:22 PM
Hi,
My problem is:
I have a master page where I have RadAjaxManager and RadScriptManager.
On my aspx page I need to call with a javascript function the server with a Ajaxrequest to update a label for example.
For that, I added a RadAjaxManagerProxy and RadCodeBlock.
When I click on the button1, that working.
Form the button2 (javascript), I called the function manager_AjaxRequest but don't refresh the label.
Do you know what I missed ?
Here is a copy of my master page and detail page.

Masterpage:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="test.master.cs" Inherits="abc.pages.MasterPage.test"  ClientIDMode="AutoID" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManagerMasterPage" runat="server" />
    <telerik:RadAjaxManager ID="RadAjaxManager_Master" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"></telerik:RadAjaxManager>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server" />
    </form>
</body>
</html>

Code begin:
protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
 
}

Detail page:
<telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server" >
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Label1"
                    LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="Button2">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Label1"
                    LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>
 
<telerik:radajaxloadingpanel id="RadAjaxLoadingPanel1" runat="server" skin="Windows7" />
 
    <telerik:RadCodeBlock  ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">
        function test() {
            var manager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
            var textBoxId = "RowSelected";
            if (manager && textBoxId) {
                manager.ajaxRequest("RowSelected");
            }
        }
    </script>
</telerik:RadCodeBlock >
 
<asp:Button ID="Button1" runat="server" Text="test 1" onclick="Button1_Click" /><br />
<asp:Button ID="Button2" runat="server" CausesValidation="false" OnClientClick="javascript:test();return false;" Text="test 2" /><br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

and the code behind:
protected void Page_Load(object sender, EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(manager_AjaxRequest);
}
 
protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = "A" + DateTime.Now.Ticks.ToString();
}
 
protected void manager_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
    if (e.Argument == "RowSelected")
    {
        Label1.Text = "B" + DateTime.Now.Ticks.ToString();
    }
}

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 13 Sep 2012, 01:24 PM
Hello Daniel,

Note that in order to update a specific control on when client ajaxRequest is calls you should add a setting in which the main RadAjaxManager updates this control. Add the following into the content page:
protected void Page_Load(object sender, EventArgs e)
{
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(manager_AjaxRequest);
    manager.AjaxSettings.AddAjaxSetting(manager, Label1);
}

Give this a try and let me know if it helps.


Greetings,
Maria Ilieva
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.
0
daniel demesmaeker
Top achievements
Rank 1
answered on 14 Sep 2012, 03:16 PM
Hi Maria,
Thank very much, that is working perfectly.
Regards,
Tags
Ajax
Asked by
daniel demesmaeker
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
daniel demesmaeker
Top achievements
Rank 1
Share this question
or