Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Ajax > AjaxRequest Event Not Firing When Using an External Javascript File (as an Embedded Resource)
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered AjaxRequest Event Not Firing When Using an External Javascript File (as an Embedded Resource)

Feed from this thread
  • not avatar

    Posted on Mar 10, 2011 (permalink)

    I've tried to narrow the problem down to a simplest scenario and here it is:

    1. Have a default.aspx with the following:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
    <%@ 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">
      
      
      <head runat="server">
        <title></title>
      </head>
      
      <body>
        <form id="form1" runat="server">   
          <telerik:radscriptmanager ID="RadScriptManagerInstance" runat="server" EnableHistory="false" EnableScriptCombine="true" />
          <telerik:radajaxmanager ID="RadAjaxManagerInstance" runat="server" />
        </form>
      </body>
        
    </html>

    2. Default.aspx's code-behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
      
    namespace WebApplication1
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //Page.ClientScript.RegisterClientScriptResource(typeof(ShelvedSessionSummary), "WebApplication1.test.js");
      
                MyControl c = this.LoadControl("MyControl.ascx") as MyControl;
                this.Form.Controls.Add(c);
                c.ModalPopUp.Show();
            }
        }
    }

    3. This is MyControl.ascx:

    <ajax:ModalPopupExtender ID="modalView" runat="server" TargetControlID="btnTrigger" PopupControlID="panelData" />
    <asp:Button ID="btnTrigger" runat="server" Style="display: none;" />
    <asp:Panel ID="panelData" runat="server" Width="400">
        <asp:Panel Height="60px" ID="panelTitle" runat="server">
            My Title
        </asp:Panel>
        <br />
        <asp:Panel ID="panelDescription" runat="server">
            <telerik:RadGrid runat="server" ID="rgData" Skin="Default" Width="886" Height="204" PageSize="5" AllowPaging="true" AllowMultiRowSelection="false" EnableLinqExpressions="false" AllowSorting="false" OnNeedDataSource="rgData_NeedDataSource" ShowFooter="false">
                <MasterTableView AutoGenerateColumns="false" ShowFooter="false">
                    <HeaderStyle Height="10px" />
                    <Columns>
                        (omitted)
                    </Columns>
                </MasterTableView>
                <PagerStyle Mode="NextPrev" />
                <ClientSettings EnableRowHoverStyle="true">
                    <Scrolling AllowScroll="false" />
                    <Selecting AllowRowSelect="True" />
                    <Resizing AllowColumnResize="true" ClipCellContentOnResize="true" EnableRealTimeResize="true" />
                    <ClientEvents OnRowClick="rowSelected" />
                </ClientSettings>
            </telerik:RadGrid>
        </asp:Panel>
    </asp:Panel>

    4. MyControl.ascx's code-behind:

    public partial class MyControl : System.Web.UI.UserControl
    {
        public AjaxControlToolkit.ModalPopupExtender ModalPopUp
        {
            get { return modalView; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            RadAjaxManager radAjaxManager = RadAjaxManager.GetCurrent(Page);
            if (radAjaxManager == null) return;
            radAjaxManager.AjaxSettings.AddAjaxSetting(radAjaxManager, rgData);
            radAjaxManager.AjaxRequest += AjaxManager_AjaxRequest;
        }
        protected void AjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            string ss = "";
        }
        protected void rgData_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            (get the data table here)
            rgData.DataSource = (data from above);
        }
    }

    5. Here's the javascript (test.js):

    function rowSelected(sender, eventArgs) {
        var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
      
        if (ajaxManager != null)
            ajaxManager.ajaxRequest("data" + "|" + eventArgs.get_itemIndexHierarchical());
    }

    Scenario that works:

    Put the javascript on the .ascx itself then everything works; i.e., my break point in AjaxManager_AjaxRequest() method gets hit.

    Scenarios that does NOT work:

    1. Seperate the javascript to its own .js file and specified its Build Action (in properties) to Embedded Resource
    2. Add [assembly: WebResource("WebApplication1.test.js", "application/x-javascript")] to the AssemblyInfo.cs
    3. Uncomment the 1st line in default.aspx's Page_Load method

    I verified that the javascript function did get called but the break point in AjaxManager_AjaxRequest() method never got hit.

    Please help.

  • not avatar

    Posted on Mar 12, 2011 (permalink)

    It's been 2 days and still no answer?

  • Tsvetoslav Tsvetoslav admin's avatar

    Posted on Mar 15, 2011 (permalink)

    Hi not,

    You cannot use server-side expressions in an external javascript file, expressions such as:
    $find"<%= RadAjaxManager.GetCurrent(Page).ClientID %>

    What you need to do is assign the ClientID of the RadAjaxManager to a global javascript variable ( var ajaxManagerID ="<%= RadAjaxManager.GetCurrent(Page).ClientID %>"  and then use it in  your external  file to get hold of the client-component of the control: $find(ajaxManagerID).

    As for the support response time - only customers with support subscription are entitled to a 24 hour response time. 

    Greetings,
    Tsvetoslav
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Ajax > AjaxRequest Event Not Firing When Using an External Javascript File (as an Embedded Resource)