Error Uncaught TypeError: Cannot read property 'ajaxRequest' of null

2 posts, 0 answers
  1. Support
    Support avatar
    13 posts
    Member since:
    Feb 2012

    Posted 22 Sep Link to this post

    Hi, I have an ascx file that contains a RadNotification and a timer.

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                    function OnClientUpdated(sender, args) {
                        sender.show()
                        $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("content");
                    }
                    function UpdateWithoutPopup() {
                        var ajaxManager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>");
                        ajaxManager.ajaxRequest(arguments);
                    }
                </script>
    </telerik:RadCodeBlock>
     
     
    <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
        <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="Timer1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadNotification1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
     
     
    <asp:Timer ID="Timer1" runat="server" Interval="6000" OnTick="Timer1_Tick" />
     
     
     <telerik:RadNotification RenderMode="Lightweight" id="RadNotification1" runat="server" loadcontenton="EveryShow"
            width="300" height="150" animation="Fade" enableroundedcorners="true" enableshadow="true"
            title="Received messages" offsetx="-20" offsety="-20" onclientupdated="OnClientUpdated"
            titleicon="none" autoclosedelay="5000" Skin="Bootstrap">
            <ContentTemplate>
                <asp:Image ID="Image1" runat="server" CssClass="Max75" />
                <asp:Literal ID="lbl" runat="server"></asp:Literal>
            </ContentTemplate>
        </telerik:RadNotification>

    the timer makes the checks and if necessary displays a popup, another calls a function

    public void Timer1_Tick(object sender, EventArgs e)
    {
            if (Check())
            {
                RadNotification1.Show();
            }
            else
            {
                string script = "UpdateWithoutPopup()";
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);
            }
        }

    When I show the popup everything works fine when if I call the error function I get the error:

    default.aspx:502 Uncaught TypeError: Cannot read property 'ajaxRequest' of null

    how do I fix?

    thanks in advance

  2. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 27 Sep Link to this post

    Hello,

    The issue is most probably caused by the following line:
    ScriptManager.RegisterStartupScript(Page, typeof(Page), "myscript", script, true);

    It is not supported to call scripts in the fashion above when using AJAX. You can check the following live sample:
    http://demos.telerik.com/aspnet-ajax/ajaxpanel/application-scenarios/recreate-scripts/defaultcs.aspx

    Regards,
    Eyup
    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top