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

Client Side Variable for RadAjaxManager

3 Answers 361 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Paige Cook
Top achievements
Rank 1
Paige Cook asked on 30 Apr 2007, 05:36 PM
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.

3 Answers, 1 is accepted

Sort by
0
Paige Cook
Top achievements
Rank 1
answered on 30 Apr 2007, 05:55 PM
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.

0
Konstantin Petkov
Telerik team
answered on 01 May 2007, 07:44 AM
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
0
Ken Fleming
Top achievements
Rank 1
answered on 01 May 2007, 04:37 PM
Except if you are trying to use the javascript in a user control loaded at runtime.
Tags
Ajax
Asked by
Paige Cook
Top achievements
Rank 1
Answers by
Paige Cook
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Ken Fleming
Top achievements
Rank 1
Share this question
or