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

Ajaxified control not getting updated

3 Answers 85 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 18 May 2010, 07:38 PM
Hi,
I have a lable control on my page which is not getting updated on an ajax callback. I can't figure out what's missing.

I have a button (cmdSearch) on my page with fires a RadWindow dialog. On the calling page I have an onClientClose handler in the javascript.

In that handler I have the followng code:
function DoDialogClose(sender)  
{  
 
    if (!sender.argument)  
        return false;  
 
    var sEventArg = "Update a Label";  
    if (sEventArg != "") {  
      
        var ram = $find("ctl00_RadAjaxManager1");  
        ram.ajaxRequest(sEventArg);   
    }  
 

It works great and the event handler on the server side gets called.
    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs)  
        If e.Argument.Length > 0 Then  
             lblMyLabel.Text = "Some text" 
        End If  
 
    End Sub  
 

I have my RadAjaxManagerProxy set as follows:
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">  
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="cmdSearch">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="lblMyLabel" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
 

The problem is that the label is never updated when I return from the Ajax call.
What am I missing?
Thanks ... Ed

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 21 May 2010, 08:27 AM
Hello Ed Staffin,

Note that when you call RadAjaxManager.ajaxRequest() client-side method, the AJAX initiator is the RadAjaxManager control. Therefore you would need to have an AJAX setting that has the RadAjaxManager as its AJAX initiator:

<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="cmdSearch"
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="lblMyLabel" />
               </UpdatedControls>
           </telerik:AjaxSetting>
           <telerik:AjaxSetting  AjaxControlID="RadAjaxManagerProxy1"
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="lblMyLabel" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
</telerik:RadAjaxManagerProxy>


I hope this helps,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ed Staffin
Top achievements
Rank 1
answered on 27 May 2010, 06:06 PM
Hi,
When I use the RadAjaxPanel I can do an async postback without a target control and just catch the update event on the server side. I have used this very successfully using something like:

        var pnl = $find("RadAjaxPanel1");  
        if(pnl)  
            pnl.ajaxRequestWithTarget("RadAjaxPanel1", "SomeArgument");  
 
And then on the server:
    Protected Sub RadAjaxPanel1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxPanel1.AjaxRequest  
        If e.Argument.Length > 0 Then  
            Dim arArgs() As String = e.Argument.Split(",")  
            If arArgs(0).Length > 0 Then  
                ' do whatever I want  
            End If  
        End If  
 
    End Sub 
I'd like to be able to do a similar operation using the RadAjaxManagerProxy.  In my example from above, cmdSearch is the initiator and lblMyLabel is what I want to update. Am I missing something?
Thanks ... Ed


0
Martin
Telerik team
answered on 01 Jun 2010, 03:45 PM
Hello Ed Staffin,

Note that when you use a RadAjaxPanel, all controls nested inside it will be updated if an AJAX call is triggered by a postback control located inside the RadAjaxPanel or by the RadAjaxPanel itself. When you call the ajaxRequestWithTarget("RadAjaxPanel1.ClientID", "SomeArgument"), an AJAX call is triggered by the panel and since the panel "knows" exactly which controls to update (all nested inside it) you can successfully update any of them on the AjaxRequest server side event handler.

However, the scenario when an RadAjaxManager is used is slightly different. The main idea of the manager is to AJAX-ify many initiator controls that update different non-adjacent controls. This is the major difference with AJAX Panel, which updates only itself (and controls that it holds). Therefore if you want to update some controls when an AJAX call is triggered by the RadAjaxManager, you would need to add a separate AJAX setting that would point which controls the RadAjaxManager should update. Otherwise the manager will fire the AjaxRequest event but since it will not know which controls to update, you will not be able to update any of them.

Based on the above, here is how sample working code looks:

<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
    <script type="text/javascript">
        function Click()
        {
            var mng = $find("<%= RadAjaxManager1.ClientID %>");
            if (mng)
                mng.ajaxRequestWithTarget(mng.get_id(), "SomeArgument");
        }
    </script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Label2" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<asp:Label runat="server" ID="Label2"></asp:Label>
<input type="button" id="Button2" onclick="Click()" value="AJAX throuhg RadAjaxManager" />

Code behind:

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
    Label2.Text = "RadAjaxManager AJAX call at:" + DateTime.Now.ToLongTimeString();
}

I hope you find this information helpful,
Martin
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Ajax
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
Martin
Telerik team
Ed Staffin
Top achievements
Rank 1
Share this question
or