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

[Solved] AjaxRequest method fires on server but client control is not updated

4 Answers 174 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
barry
Top achievements
Rank 1
barry asked on 19 May 2008, 03:01 PM
Hi, i am having a problem with my AjaxRequest method that i have hooked up to the onchange event of a dynamically created button. It seems to work fine in that the server side method fires and calls a method I have for calculationg a count. The problem is that i update a client side label with this count but the label on the page does not get updated. The weird thing is that on the same page I have a button that calls the same server side method which updates the label correctly as you would expect. Can anyone see how i am going wrong or why the label is not getting updated?

this is my javascript:
        function InitiateAjaxRequest(arguments) 
        { 
            var ajaxManager = <%= RadAjaxManager1.ClientID %>; 
            ajaxManager.AjaxRequest(arguments); 
        } 
this is my ajax manager code that contains the reference to the serverside onajaxrequest method and also the panel that is being refreshed via the button click:
    <rad:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" > 
        <AjaxSettings> 
            <rad:AjaxSetting AjaxControlID="RadAjaxManager1"
            </rad:AjaxSetting> 
            <rad:AjaxSetting AjaxControlID="pnlNumberPresent"
                <UpdatedControls> 
                    <rad:AjaxUpdatedControl ControlID="pnlNumberPresent" /> 
                </UpdatedControls> 
            </rad:AjaxSetting> 
        </AjaxSettings> 
    </rad:RadAjaxManager> 

this is the ajaxified button and the label to be refreshed
<asp:Panel  ID="pnlNumberPresent" CssClass="row" runat="server" Visible="True" > 
  <asp:Label  id="lblNumberPresent" runat="server"  Visible="true" Cssclass="field_label_noclear" /> 
  <asp:Button  id="btnRefreshNumberPresent"  Cssclass="input_but" text="Refresh" runat ="server" OnClick="calculateNumberPresent" /> 
</asp:Panel> 
                   


this is where i am dynamically building my textbox(s)

 if (bJavaScriptEnabled) 
            { 
                int nextTextboxNo = StudentCount + 1; 
                statusBox.Attributes.Add("onchange""InitiateAjaxRequest(this,event); return false;"); 
                statusBox.Attributes.Add("onkeypress""setFocusOnEnterKey('status_textbox_" + nextTextboxNo.ToString() + "',event);"); 
            } 


and this is the server side method that is called when I click the button directly and also the onajaxrequest method that calls the same method:
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
    { 
        calculateNumberPresent(sender, e); 
    } 
 
    protected void calculateNumberPresent(object sender, EventArgs e) 
    { 
        int intCount = 0
 
        //code to do count here... 
 
        lblNumberPresent.Text = "Total number of students present = " + intCount; 
    } 

on both events the "lblNumberPresent.Text = "Total number of students present = " + intCount;"
line is hit in the debugger but it is only on the button click that the label on the page gets updated...


4 Answers, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 19 May 2008, 03:56 PM
Hi barry,

When using AjaxRequest the initiator is the AjaxManager. Looking at your AjaxSettings, you have the AjaxManager added as initiator, but do not have updated controls. You should add the pnlNumberPresent or lblNumberPresent as updated control in order to update it.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
barry
Top achievements
Rank 1
answered on 19 May 2008, 04:09 PM
Hi steve,
Thanks for the quick reply

I do have pnlNumberPresent as an UpdateControl, unless the syntax is wrong:

<rad:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" > 
        <AjaxSettings> 
            <rad:AjaxSetting AjaxControlID="RadAjaxManager1"
            </rad:AjaxSetting> 
            <rad:AjaxSetting AjaxControlID="pnlNumberPresent"
                <UpdatedControls> 
                    <rad:AjaxUpdatedControl ControlID="pnlNumberPresent" /> 
                </UpdatedControls> 
            </rad:AjaxSetting> 
        </AjaxSettings> 
    </rad:RadAjaxManager> 


Can you confirm if this is correct?

Cheers,
Barry
0
Steve
Telerik team
answered on 20 May 2008, 08:14 AM
Hi Barry,

Yes, the syntax is wrong. The correct AjaxSettings for initiator and updated controls should be like this:

  <rad:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <rad:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <rad:AjaxUpdatedControl ControlID="pnlNumberPresent" />
                    </UpdatedControls>
                </rad:AjaxSetting>
            </AjaxSettings>
        </rad:RadAjaxManager>

Greetings,
Steve
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
barry
Top achievements
Rank 1
answered on 20 May 2008, 08:39 AM
Hi Steve,
Thanks for that, would you believe i had just re-read your first reply and spotted the problem as you had suggested, the correct code is quite rightly:


    <rad:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" > 
        <AjaxSettings> 
            <rad:AjaxSetting AjaxControlID="RadAjaxManager1"
               <UpdatedControls> 
                    <rad:AjaxUpdatedControl ControlID="pnlNumberPresent" /> 
                </UpdatedControls> 
            </rad:AjaxSetting> 
            <rad:AjaxSetting AjaxControlID="pnlNumberPresent"
                <UpdatedControls> 
                    <rad:AjaxUpdatedControl ControlID="pnlNumberPresent" /> 
                </UpdatedControls> 
            </rad:AjaxSetting> 
        </AjaxSettings> 
    </rad:RadAjaxManager> 

thanks for all your help
barry
Tags
Ajax
Asked by
barry
Top achievements
Rank 1
Answers by
Steve
Telerik team
barry
Top achievements
Rank 1
Share this question
or