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

ajax manager is null

2 Answers 34 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
priya nallaperumal
Top achievements
Rank 1
priya nallaperumal asked on 24 Jan 2011, 01:20 PM
Hello!
i have attached my code below.


 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
        <UpdatedControls>
       <telerik:AjaxUpdatedControl ControlID="panel1" />
      <telerik:AjaxUpdatedControl ControlID="samplediv" />
        </UpdatedControls>
        </telerik:AjaxSetting>
        </AjaxSettings>
       <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Timer1" >
        <UpdatedControls>
        <telerik:AjaxUpdatedControl ControlID="samplediv" />
        <telerik:AjaxUpdatedControl ControlID="ajaxbtn" />
        </UpdatedControls>
        </telerik:AjaxSetting>
        </AjaxSettings>
        </telerik:RadAjaxManager>
        <br />
         <asp:Panel ID="panel1" runat="server">
        <asp:Timer ID="Timer1" runat="server" Interval="2000" ontick="Timer1_Tick" Enabled="false">
        </asp:Timer></asp:Panel>
        <div id="samplediv" runat="server" style="border:solid 1px grey;height:180px;width:250px;overflow:scroll;" />  
<telerik:RadCodeBlock ID="radblk" runat="server">
 <script type="text/javascript">
function chattext()
{
    var ajaxmagr = $find("<%=RadAjaxManager1.ClientID%>");
    alert(ajaxmagr);
    ajaxmagr.ajaxRequest("chat");
}

</script>       
        </telerik:RadCodeBlock>


cs code..


protected void Timer1_Tick(object sender, EventArgs e)
    {
        string s = "chattext();";
        RadScriptManager.RegisterStartupScript(this, this.GetType(), "s", s, true);
    }
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "chat")
        {
            
            samplediv.InnerHtml += " sample text <br/>";
           
        }
    }






i want to call a js funtion in timer tick.  but i got ajaxmgr as null in js alert.
whats wrong in my code? 

thanks.
priya.

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 27 Jan 2011, 03:55 PM
Hello,

It seems that the Startup script is registered too early on the page and the RadAjaxManager is still not initialized. please try to set time out like this:
<script type="text/javascript">
     function chattext() {
         setTimeout(function () {
             var ajaxmagr = $find("<%= RadAjaxManager1.ClientID %>");
             alert(ajaxmagr);
             ajaxmagr.ajaxRequest("chat");
        }, 0);
     }
  
</script>
 
Let me know if this helps.

Kind regards,
Maria Ilieva
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Prashant Nandha
Top achievements
Rank 1
answered on 28 Oct 2013, 05:20 PM
This is great, it worked for me.
Tags
Ajax
Asked by
priya nallaperumal
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Prashant Nandha
Top achievements
Rank 1
Share this question
or