ajaxRequest from User Control doesn't update embedded control

3 posts, 1 answers
  1. Francois MARTIN
    Francois MARTIN avatar
    44 posts
    Member since:
    Aug 2005

    Posted 22 Apr 2008 Link to this post

    A simple WebForm contains a user control with a RadAjaxPanel.
    The user control contains a button that is supposed to fire the ajaxRequest method of the RadAjaxPanel and update a simple label... but it doesn't!

    The function ajaxRequest is indeed called, but the label is never updated.

    Source code:

    Test.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %> 
     
    <%@ Register src="AjaxControl.ascx" tagname="AjaxControl" tagprefix="uc1" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title>Test</title> 
    </head> 
    <body> 
        <form id="form1" runat="server">  
        <div> 
            <asp:ScriptManager ID="ScriptManager1" runat="server">  
            </asp:ScriptManager> 
            <asp:Label ID="Label1" runat="server" Text="Click on the button..."></asp:Label><br /> 
            <uc1:AjaxControl ID="AjaxControl1" runat="server" /> 
              
        </div> 
        </form> 
    </body> 
    </html> 
     

    AjaxControl.aspx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AjaxControl.ascx.cs" Inherits="AjaxControl" %> 
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
     
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">  
        <script type="text/javascript">  
        function InitiateAsyncRequest(argument)  
        {  
            var ajaxPanel = $find("<%=RadAjaxPanel1.ClientID%>");  
     
            ajaxPanel.ajaxRequest(argument);  
        }  
        </script> 
    </telerik:RadCodeBlock> 
     
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="InitiateAsyncRequest('New Text')" /> 
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" 
        runat="server" Height="200px" Width="300px" OnAjaxRequest="RadAjaxPanel1_AjaxRequest">  
        <asp:Label ID="Label1" runat="server" Text="...and this text will change!"></asp:Label> 
    </telerik:RadAjaxPanel> 
     

    AjaxControl.aspx.cs:

    using System;  
    using System.Collections;  
    using System.Configuration;  
    using System.Data;  
    using System.Linq;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
    using System.Xml.Linq;  
     
    public partial class AjaxControl : System.Web.UI.UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
     
        }  
     
        protected void RadAjaxPanel1_AjaxRequest(object source, Telerik.Web.UI.AjaxRequestEventArgs e)  
        {  
            Label1.Text = e.Argument;  
        }  
    }  
     

  2. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 22 Apr 2008 Link to this post

    Hi Francois,

    Haven't you noticed that clicking the button causes postback rather than ajax request? The problem is coming from the default behavior of the asp:Buttons which always submit the form, unless you return false to override this behavior. Change the OnClientClick handler like this:

    OnClientClick="InitiateAsyncRequest('New Text'); return false;"

    Regards,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Francois MARTIN
    Francois MARTIN avatar
    44 posts
    Member since:
    Aug 2005

    Posted 22 Apr 2008 Link to this post

    Oops. You are right of course...
    Thank you!
Back to Top