Javascript object disappears on second firing of event

2 posts, 0 answers
  1. Richard Branham
    Richard Branham avatar
    12 posts
    Member since:
    Sep 2009

    Posted 15 Jan 2010 Link to this post

    I have a simple project consisting of 2 pages.  The first page contains a button, a RadAjaxManager, a RadWindow, and a RadGrid.  The second page contains only some text and is used as a placeholder in the RadWindow. 

    I am executing an event handler for the RadWindow OnClientClose event, and in the handler I'm executing the ajaxRequest method on the RadAjaxManager.  When the ajaxRequest call is made, the server-side handler is called as expected.

    The problem is this:  the code works fine the first time the RadWindow is closed.  However, if I click the button and open the window a second time and then close the window, the RadAjaxManager client object is null when the OnClientClose event handler is fired the second time.  Is this expected behavior?

    This occurs in the handlers for both the OnClientClose event for the RadWindow and for the RadWindowManager.  It appears that the RadAjaxManager object is destroyed when the RadWindow is closed.

    Any thoughts as to why the RadAjaxManager goes away?


    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RouteLegs.aspx.cs" Inherits="CNIntegration.RouteLegs" %> 
     
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
     
    <!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></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <div> 
            <script type="text/javascript"
                function ClientClose() { 
                    try { 
                        var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>"); 
                        alert(ajaxManager); 
                        ajaxManager.ajaxRequest("Rebind"); 
                        alert("Returned from ajaxRequest"); 
                    } 
                    catch (err) { 
                        alert("Error:  " + err.message); 
                    } 
                         
                } 
            </script> 
     
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            </telerik:RadAjaxManager> 
             
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
            </telerik:RadScriptManager> 
     
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
                <Windows> 
                    <telerik:RadWindow ID="windowWaypoints" runat="server" Behavior="Default" OnClientClose="ClientClose" OnClientShow="ClientClose" 
                        InitialBehavior="None" Left="" NavigateUrl="Waypoints.aspx" OpenerElementID="Button1" 
                        Top="" Animation="None" Modal="true" Height="500" Width="500"
                    </telerik:RadWindow> 
                </Windows> 
            </telerik:RadWindowManager> 
             
            <telerik:RadDock ID="RadDock1" runat="server" Width="300px" Visible="false" Resizable="true"
                <ContentTemplate> 
                    <telerik:RadComboBox ID="RadComboBox1" runat="server"
                    </telerik:RadComboBox> 
                    <telerik:RadTextBox ID="RadTextBox1" runat="server"
                    </telerik:RadTextBox> 
                </ContentTemplate> 
            </telerik:RadDock> 
             
            <%--<asp:LinkButton ID="LinkButton1" runat="server">Create New Waypoint</asp:LinkButton>--%> 
            <asp:Button ID="Button1" runat="server" Text="Button" /> 
             
            <telerik:RadGrid ID="gridRates" runat="server"  
                onneeddatasource="gridRates_NeedDataSource" AllowFilteringByColumn="True"  
                AllowPaging="True" AllowSorting="True" GridLines="None" ShowFooter="True" > 
                <MasterTableView> 
                    <RowIndicatorColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </RowIndicatorColumn> 
                    <ExpandCollapseColumn> 
                        <HeaderStyle Width="20px"></HeaderStyle> 
                    </ExpandCollapseColumn> 
                </MasterTableView> 
                <ClientSettings> 
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" /> 
                </ClientSettings> 
            </telerik:RadGrid> 
             
        </div> 
        </form> 
    </body> 
    </html> 
     



    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Data; 
    using Telerik.Web.UI; 
     
    namespace CNIntegration 
        public partial class RouteLegs : System.Web.UI.Page 
        { 
            protected void Page_Load(object sender, EventArgs e) 
            { 
                gridRates.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top; 
                gridRates.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true
            } 
     
     
            protected override void RaisePostBackEvent(IPostBackEventHandler source, String eventArgument) 
            { 
                base.RaisePostBackEvent(source, eventArgument); 
                if (source is RadAjaxManager) 
                { 
                    switch (eventArgument) 
                    { 
                        case "Rebind"
                            { 
                                gridRates.Rebind(); 
                                break
                            } 
                    } 
                } 
            } 
             
            private DataSet GetRateData() 
            { 
                DataSet ds = new DataSet(); 
                ds.Tables.Add("Rates"); 
                ds.Tables[0].Columns.Add("RateID"); 
                ds.Tables[0].Columns.Add("RateName"); 
                ds.Tables[0].Columns.Add("RateDesc"); 
     
                DataRow dr = ds.Tables[0].NewRow(); 
                dr["RateID"] = 1; 
                dr["RateName"] = "First Rate"
                dr["RateDesc"] = "Desc One"
                ds.Tables[0].Rows.Add(dr); 
     
                dr = ds.Tables[0].NewRow(); 
                dr["RateID"] = 2; 
                dr["RateName"] = "Second Rate"
                dr["RateDesc"] = "Desc Two"
                ds.Tables[0].Rows.Add(dr); 
     
                Session["RateData"] = ds; 
     
                return ds; 
            } 
     
            protected void gridRates_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) 
            { 
                gridRates.DataSource = GetRateData(); 
            } 
     
            /*
            protected void gridRates_ItemCommand(object source, GridCommandEventArgs e)
            {
                DataSet ds = new DataSet();
                ds.Tables.Add("Rates");
                ds.Tables[0].Columns.Add("RateID");
                ds.Tables[0].Columns.Add("RateName");
                ds.Tables[0].Columns.Add("RateDesc");
                gridRates.DataSource = ds;
            }
            */ 
        } // RouteLegs class 
    // CNIntegration namespace 
     


  2. Richard Branham
    Richard Branham avatar
    12 posts
    Member since:
    Sep 2009

    Posted 15 Jan 2010 Link to this post

    This appears to have fixed the issue:  http://www.telerik.com/community/forums/aspnet-ajax/ajax/find-ajaxmanager-returns-null-after-second-request.aspx

    Putting the RadScriptManager before the RadAjaxManager seems to have fixed it.
Back to Top