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

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

12 Answers 104 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
CH
Top achievements
Rank 1
CH asked on 11 Feb 2011, 08:58 AM
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.

12 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 14 Feb 2011, 05:24 PM
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.
0
CH
Top achievements
Rank 1
answered on 15 Feb 2011, 01:57 AM
Hi Tsvetoslav ,
Thanks for your reply, i will try it out.

Regards,
ChuinHun
0
CH
Top achievements
Rank 1
answered on 15 Feb 2011, 03:06 AM
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

0
Tsvetoslav
Telerik team
answered on 15 Feb 2011, 10:05 AM
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.
0
Craig Riter
Top achievements
Rank 1
answered on 11 Apr 2011, 05:27 AM
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?
0
Sebastian
Telerik team
answered on 11 Apr 2011, 08:57 AM
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
0
Content and Code
Top achievements
Rank 1
answered on 07 Mar 2012, 10:47 AM

 

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 

0
Pavlina
Telerik team
answered on 07 Mar 2012, 01:34 PM
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.
0
Ali
Top achievements
Rank 1
answered on 27 May 2013, 04:40 PM
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.
0
Pavlina
Telerik team
answered on 30 May 2013, 12:30 PM
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.
0
Catalin
Top achievements
Rank 1
answered on 07 Sep 2013, 08:35 PM
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
0
Plamen
Telerik team
answered on 10 Sep 2013, 12:06 PM
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.
Tags
Ajax
Asked by
CH
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
CH
Top achievements
Rank 1
Craig Riter
Top achievements
Rank 1
Sebastian
Telerik team
Content and Code
Top achievements
Rank 1
Pavlina
Telerik team
Ali
Top achievements
Rank 1
Catalin
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or