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

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

1 Answer 937 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Support
Top achievements
Rank 2
Support asked on 22 Sep 2016, 01:34 PM

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

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 27 Sep 2016, 12:49 PM
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.
Tags
Ajax
Asked by
Support
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Share this question
or