Client Side Variable for RadAjaxManager

4 posts, 0 answers
  1. Paige Cook
    Paige Cook avatar
    14 posts
    Member since:
    Dec 2006

    Posted 30 Apr 2007 Link to this post

    Before the Prometheus version of RadAjaxManager I could have a page like the following where I emit from the code-behind a client side variable that would reference the client side instance of the RadAjaxManager.

    ASPX Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> 
    <%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %> 
     
    <!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>Untitled Page</title> 
        <script type="text/javascript"
                function TextBoxCustomAjax(eventArgs) 
                {      
                    ajaxMgr.AjaxRequest(eventArgs); 
                } 
        </script> 
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
                <asp:TextBox ID="TextBox1" onkeyup="TextBoxCustomAjax('TextBox1');" runat="server" /> 
                <br /> 
                <asp:Label ID="Label1" runat="server" /> 
        </div> 
            <radA:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableOutsideScripts="true" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
                <AjaxSettings> 
                    <radA:AjaxSetting AjaxControlID="RadAjaxManager1"
                        <UpdatedControls> 
                            <radA:AjaxUpdatedControl ControlID="Label1" /> 
                        </UpdatedControls> 
                    </radA:AjaxSetting> 
                </AjaxSettings> 
            </radA:RadAjaxManager> 
        </form> 
    </body> 
    </html> 
     


    Code Behind:
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
     
    public partial class _Default : System.Web.UI.Page  
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.ClientScript.IsStartupScriptRegistered("AjaxManager")) 
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "AjaxManager"string.Format("var ajaxMgr = {0};",RadAjaxManager1.ClientID), true); 
        } 
     
     
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
        { 
            if (e.Argument == TextBox1.ClientID) 
            { 
                Label1.Text = TextBox1.Text; 
            } 
        } 

    Today, I converted the same code to use the new Prometheus version of RadAjaxManager and I get the following JavaScript error when function TextBoxCustomAjax is called: "Object does not support this property or method".

    Here is the code that is using the Prometheus version:

    ASPX Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"
    <head runat="server"
        <title>Untitled Page</title> 
        <script type="text/javascript"
                function TextBoxCustomAjax(eventArgs) 
                {      
                    ajaxMgr.AjaxRequest(eventArgs); 
                } 
        </script> 
    </head> 
    <body> 
        <form id="form1" runat="server"
            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <div> 
                <asp:TextBox ID="TextBox1" onkeyup="TextBoxCustomAjax('TextBox1');" runat="server" /> 
                <br /> 
                <asp:Label ID="Label1" runat="server" /> 
            </div> 
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="Label1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
        </form> 
    </body> 
    </html> 
     

    Code Behind:
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
     
    public partial class _Default : System.Web.UI.Page  
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.ClientScript.IsStartupScriptRegistered("AjaxManager")) 
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "AjaxManager"string.Format("var ajaxMgr = {0};",RadAjaxManager1.ClientID), true); 
        } 
     
     
        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
        { 
            if (e.Argument == TextBox1.ClientID) 
            { 
                Label1.Text = TextBox1.Text; 
            } 
        } 

    Is there a way to accomplish this same functionality using the Prometheus version of the RadAjaxManager. I can change the line in TextBoxCustomAjax to:
    <%=RadAjaxManger1.ClientID %>.AjaxRequest(eventargs);
    and that will work, but that is not ideal for my current scenario.

    Thanks.
  2. Paige Cook
    Paige Cook avatar
    14 posts
    Member since:
    Dec 2006

    Posted 30 Apr 2007 Link to this post

    I actually played around a little bit with this and modified my code client side as follows and this worked:

                function getAjaxMgr() 
                { 
                    return <%=RadAjaxManager1.ClientID %>; 
                } 
                function TextBoxCustomAjax(eventArgs) 
                {      
                    getAjaxMgr().AjaxRequest(eventArgs); 
                    //ajaxMgr.AjaxRequest(eventArgs); 
                } 
     

    But I still wonder if there is a better way to do this.... especially since there can only ever be one instance of the RadAjaxManager on a page, it would be nice if the there was a common function like that to get the instance on the client side.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Konstantin Petkov
    Admin
    Konstantin Petkov avatar
    1911 posts

    Posted 01 May 2007 Link to this post

    Hello Paige Cook,

    Prometheus RadAjax API (both client and server-side) is exactly the same as in regular RadAjax, so you can use the same approach as before to accomplish this. Here is the Client-Side API help article of Prometheus RadAjax:

    http://www.telerik.com/help/radcontrols/prometheus/ajxClientSideAPI.html

    I suggest you also review the following forum thread in this forum elaborating on getting manager instance:

    http://www.telerik.com/community/forums/thread/b311D-ththc.aspx

    Best wishes,
    Konstantin Petkov
    the telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Ken Fleming
    Ken Fleming avatar
    12 posts
    Member since:
    Apr 2007

    Posted 01 May 2007 Link to this post

    Except if you are trying to use the javascript in a user control loaded at runtime.
Back to Top