AJAX not firing up for the first time in SharePoint 2010 Visual webpart

13 posts, 0 answers
  1. CH
    CH avatar
    48 posts
    Member since:
    Aug 2010

    Posted 11 Feb 2011 Link to this post

    Hi,

    I try to create a simple application using Telerik AJAX manager and below is my code:
    VisualWebpart.ascx
    <telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server" >
          <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="btn">
                     <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="lbl" LoadingPanelID="load1"  />
                     </UpdatedControls>
            </telerik:AjaxSetting>
          </AjaxSettings>
    </telerik:RadAjaxManagerProxy>
     
     <asp:label ID="lbl" runat=server />
     <asp:Button ID="btn" runat=server Text="press" onclick="btn_Click" />

    In my VisualWebpart.ascx.cs
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;

    namespace DPA.DPINET.ResourceBooking.View.CalendarVW
    {
        public partial class CalendarVWUserControl : UserControl
        {
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                EnsureChildControls();
            }
            protected void Page_Load(object sender, EventArgs e)
            {
               
              
            }

            protected void btn_Click(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(3000);
                lbl.Text = DateTime.Now.ToString();
            }
        }
    }


    In my Master Page:
    <asp:ScriptManager id="ScriptManager" runat="server" EnablePageMethods="false" EnablePartialRendering="true" EnableScriptGlobalization="false" EnableScriptLocalization="true" />
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
       </telerik:RadAjaxManager>
     <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>

    My first click it did a postback, but the following click it did ajax call, only thing that the LoadingPanel didnt show up. This code work in normal ASP.NET page, but when try to move to my VisualWebPart annd deploy over to sharePoint 2010, it fail. Please advice.
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Feb 2011 Link to this post

    Hi chuin hun,

    Attached is a small sample that demonstrates how you should ajaxify controls in sharepoint when the controls being ajaxified are within a user control.

    Regards,
    Tsvetoslav
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. CH
    CH avatar
    48 posts
    Member since:
    Aug 2010

    Posted 14 Feb 2011 Link to this post

    Hi Tsvetoslav ,
    Thanks for your reply, i will try it out.

    Regards,
    ChuinHun
  5. CH
    CH avatar
    48 posts
    Member since:
    Aug 2010

    Posted 14 Feb 2011 Link to this post

    Hi,
    I dont seem to get it working at my end. Below is my code:

    MainMenu.cs (the webpart .cs)
    using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using Telerik.Web.UI;
    namespace DPA.DPINET.Views.MainMenu.MainMenu
    {
        [ToolboxItemAttribute(false)]
        public class MainMenu : WebPart
        {
            RadAjaxManagerProxy ajaxmgrProxy;
     
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                ajaxmgrProxy = new RadAjaxManagerProxy();
     
                Page.Items.Add(typeof(RadAjaxManagerProxy), ajaxmgrProxy);  
            }
            // Visual Studio might automatically update this path when you change the Visual Web Part project item.
            private const string _ascxPath = @"~/_CONTROLTEMPLATES/DPA.DPINET.Views.MainMenu/MainMenu/MainMenuUserControl.ascx";
     
            protected override void CreateChildControls()
            {
                Control control = Page.LoadControl(_ascxPath);
                Controls.Add(control);
                Panel panel = control.FindControl("ListViewPanel1") as Panel;
                Button btn = control.FindControl("btn") as Button;
                RadAjaxLoadingPanel loadingPanel = control.FindControl("RadAjaxLoadingPanel1") as RadAjaxLoadingPanel;
                ajaxmgrProxy.AjaxSettings.AddAjaxSetting(panel, panel, loadingPanel);
                ajaxmgrProxy.AjaxSettings.AddAjaxSetting(panel, btn, loadingPanel);
            }
        }
    }

    MainMenuControl.ascx (My visual webpart acsc)
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MainMenuUserControl.ascx.cs" Inherits="DPA.DPINET.Views.MainMenu.MainMenu.MainMenuUserControl" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2010.3.1109.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>
     
            <asp:Panel ID="ListViewPanel1" runat="server">
                <asp:Label ID="lbl" runat="server" />
                <asp:Button ID=btn runat=server Text="push me" onclick="btn_Click" />
            </asp:Panel>

    MainMenuControl.ascx.cs
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.Web.UI;
     
     
    namespace DPA.DPINET.Views.MainMenu.MainMenu
    {
        public partial class MainMenuUserControl : UserControl
        {
           
          
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
               
            }
            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
            protected void btn_Click(object sender, EventArgs e)
            {
                lbl.Text = DateTime.Now.ToString();
            }
             
        }
    }

    I am using RadAjaxManagerProxy as i already have RadAjaxManager in my master page.
    please advice.

    Regards,
    ChuinHun

  6. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 15 Feb 2011 Link to this post

    Hi chuin,

    RadAjaxManagerProxy is designed for design-time purpose only - to facilitate the ajaxification of the controls you are using the Visual Studio designer. In your case, this is not applicable - so you should use RadAjaxManager instead. You can get it anywhere in your code as follows:

    RadAjaxManager.GetCurrent(Page);


    Hope it helps.

    Greetings,
    Tsvetoslav
    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.
  7. Craig Riter
    Craig Riter avatar
    2 posts
    Member since:
    Feb 2010

    Posted 11 Apr 2011 Link to this post

    I'm trying to implement "Load On Demand Grid in ComboBox"
    http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridincombobox/defaultcs.aspx?product=combobox  which requires the OnAjaxRequest event to be handled in code to perform some actions.   If I have the RadAjaxManager on the masterpage as shown how can the webpart control hook in so that the code will be executed?
  8. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 11 Apr 2011 Link to this post

    Hi Craig,

    You have two options for your scenario:

    Best regards,

    Sebastian
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Content and Code
    Content and Code avatar
    26 posts
    Member since:
    Oct 2004

    Posted 07 Mar 2012 Link to this post

     

    Your project does not work. The grid loads the first time but as soon as I sort I get the following error:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

     

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Source Error:

     

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).] System.Web.UI.ControlCollection.Add(Control child) +11019898 Microsoft.SharePoint.Publishing.PublishingLayoutPage.OnLoad(EventArgs e) +212 System.Web.UI.Control.LoadRecursive() +66 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428 

  10. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 07 Mar 2012 Link to this post

    Hi,

    Could you please try to wrap your JavaScript code (no matter whether it is in the head section or not) in RadCodeBlock as depicted in the following article?
    http://www.telerik.com/help/aspnet-ajax/ajax-radscriptblock-radcodeblock.html

    Kind regards,
    Pavlina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  11. Ali
    Ali avatar
    2 posts
    Member since:
    Dec 2006

    Posted 27 May 2013 Link to this post

    I am facing the same issue.
    I have used the telerik controls on the visual webpart.First event on the page is always postback and then later it gets ajaxified.

    Master Page Contains :
    Script Manager (Sharepoint)
    RadajaxManager and Loading Panel

    Visual Webpart
    RadAjaxManagerProxy
    Event Buttons


    Please advice.
  12. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 30 May 2013 Link to this post

    Hi Ali,

    Can you specify if you are using SharePoint 2010 or 2013? In case you are using SharePoint 2010 you can refer to the attached project which shows how to ajaxify controls properly. Give it a try and let me know if it helps.

    Regards,
    Pavlina
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  13. Catalin
    Catalin avatar
    7 posts
    Member since:
    Mar 2011

    Posted 07 Sep 2013 Link to this post

    Hi Pavlina,
    I'm using Telerik 2013.2.717.35 in Sharepoint 2010 with the latest cumulative update applied.
    The project you've attached works perfectly with the RadGridin SP2010. I cannot say the same for the RadScheduler. Soon you start to changing the views of the radScheduler everything freeze on the page due of some js errors. You get the view switched but this is the last thing you get.
    These errors varies on the target view changed:
    -from Month view to Week: a.WeekModel is not a constructor
    -from Month view to Day: a.DayModel is not a constructor... and so on
    I know that RadScheduler it's a more heavier control than RadGrid in terms of js scripts loaded but it should be a different solution available than setting up EnableEmbededScripts="false" and loading from the code behind on the prerender these scripts how some of your colleagues suggested already. I'm not considering that like a real solution because I know Telerik offers now the radScheduler Webpart specially done for SharePoint which I suppose it's Ajaxfied and you can change the views without errors.
    Why don't you integrate this knowledge in the regular components for everybody else who want to use the regular components in Sharepoint ?
    Regards,
    Cata
  14. Plamen
    Admin
    Plamen avatar
    2734 posts

    Posted 10 Sep 2013 Link to this post

    Hi Cata,

     
    Thank you for sharing your opinion and observation with us. 

    The issue is known bug indeed and we will make our best to fix it as soon as possible. Please excuse us for the inconveniences caused by it.

    If you have further suggestions please don't hesitate to share them again.

    Regards,
    Plamen
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017