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

sharepoint 2010 and radajax

7 Answers 40 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Hans
Top achievements
Rank 1
Hans asked on 03 Jan 2014, 06:50 PM
Hi

I have some problems with radajax when I use it in webparts created for sharepoint 2010.
I used Visual studio 2012.

For example I have a grid with EditMode = InPlace or EditForms

When I edit a row , fill in a radtextbox and save the form , the  save function will have the old value of the radtextbox, not the modified one.
If I try to edit a rad datepicker, , it not shows the calendar.

If I take out the radajax, the previous operation are working just fine.

Can you help me please,

I can send you a demo if you want

Thank you !
Hans

7 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 08 Jan 2014, 12:29 PM
Hello,

Please note that ajaxifying the telerik controls that are positioned within a user controls works somewhat differently from the scenario when they are loaded directly on a web form. In you case, you need to move the RadAjaxManager control to the web part class, create it there and add it to the Controls collection of the web part as follows:
private RadAjaxManager _ajaxManager;
  
protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
  
    SetUpAjaxManagerOnPage();
  
    EnsureChildControls();
}
  
  
protected void SetUpAjaxManagerOnPage()
{
    RadAjaxManager currentAjaxManager = RadAjaxManager.GetCurrent(Page);
  
    if (currentAjaxManager == null)
    {
        Page.Form.Controls.AddAt(0, AjaxManager);
        Page.Items.Add(typeof(RadAjaxManager), AjaxManager);
    }
}
  
protected virtual RadAjaxManager AjaxManager
{
    get
    {
        if (_ajaxManager == null)
        {
            _ajaxManager = RadAjaxManager.GetCurrent(Page);
  
            if (_ajaxManager == null)
            {
                _ajaxManager = new RadAjaxManager() { ID = "RadAjaxManager1" };
            }
        }
  
        return _ajaxManager;
    }
}

Then in the OnLoad event of the web part, get the RadAjaxManager as follows:
RadAjaxManager _manager = RadAjaxManager.GetCurrent(Page);

and add your ajax settings programmatically. Beforehand, you should have the user control in the CreateChildControls method of the web part and there through FindControl you should retrieve the controls to ajaxify. Keep them in a private variable local to the web part class and use that in the OnLoad event to dynamically add the ajax settings.


Hope this information will prove helpful.

Regards,
Maria Ilieva
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 the blog feed now.
0
Hans
Top achievements
Rank 1
answered on 08 Jan 2014, 06:24 PM
Hi !

I've done how you said and I have a java script error like in the picture attached. I can send you a test project but I don't know how. I try it on 2 development server and a production server and I got the same error everywhere !

Please help,
Hans
0
Maria Ilieva
Telerik team
answered on 13 Jan 2014, 01:26 PM
Hello,

The presented error most commonly appear in case the Ajax settings are not properly configured.  Therefor could you please send the code form the WebPart file and the related WebUserControl markup and code behind? Thus we will be able to revise your logic further and do our best to isolate the root cause of the issue.


Regards,
Maria Ilieva
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 the blog feed now.
0
Hans
Top achievements
Rank 1
answered on 13 Jan 2014, 03:37 PM

 

This is the web part cs file :

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using System.Web.UI;
 
 
 
 
namespace Example.Demo
{
    [ToolboxItemAttribute(false)]
    public partial class Demo : WebPart
    {
        // Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
        // using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
        // for production. Because the SecurityPermission attribute bypasses the security check for callers of
        // your constructor, it's not recommended for production purposes.
        // [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
               
        private RadAjaxManager _ajaxManager;
        private const string _ascxPath = @"~/_controltemplates/Example/emp.ascx";
        private Panel p = null;
        private RadAjaxLoadingPanel lp = null;
 
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
 
            SetUpAjaxManagerOnPage();
 
            EnsureChildControls();
        }
 
        protected void SetUpAjaxManagerOnPage()
        {
            RadAjaxManager currentAjaxManager = RadAjaxManager.GetCurrent(Page);
            if (currentAjaxManager == null)
            {
                Page.Form.Controls.AddAt(0, AjaxManager);
                Page.Items.Add(typeof(RadAjaxManager), AjaxManager);
            }
        }
 
        protected virtual RadAjaxManager AjaxManager
        {
            get
            {
                if (_ajaxManager == null)
                {
                    _ajaxManager = RadAjaxManager.GetCurrent(Page);
 
                    if (_ajaxManager == null)
                    {
                        _ajaxManager = new RadAjaxManager() { ID = "RadAjaxManager1" };
                    }
                }
 
                return _ajaxManager;
            }
        }
 
        protected override void CreateChildControls()
        {
            Control control = Page.LoadControl(_ascxPath);
            p = control.FindControl("DemoPanel") as Panel;
            lp = control.FindControl("Demo_LoadingPanel") as RadAjaxLoadingPanel;
            Controls.Add(control);
        }
 
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            RadAjaxManager _manager = RadAjaxManager.GetCurrent(Page);
            _manager.AjaxSettings.AddAjaxSetting(p, p, lp);
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
 
 
        }
 
    }
 
    
}


and this is the control's ascx file

<%@ 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="emp.ascx.cs" Inherits="Example.ControlTemplates.Example.emp" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2013.2.717.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<telerik:RadAjaxLoadingPanel ID="Demo_LoadingPanel" runat="server" Skin="Black" />
<asp:Panel ID="DemoPanel" runat="server" Width="70%">
    <telerik:RadGrid ID="DemoGrid" runat="server" Skin="Black"
        OnNeedDataSource="DemoGrid_NeedDataSource"
        OnInsertCommand="DemoGrid_ItemInsert" OnUpdateCommand="DemoGrid_ItemUpdate" Width="70%">
 
        <MasterTableView CommandItemDisplay="Top" DataKeyNames="Id" AutoGenerateColumns="false" HeaderStyle-Font-Bold="true">
            <Columns>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn UniqueName="Id" HeaderText="ID" DataField="Id">
                    <HeaderStyle ForeColor="Silver" Width="20px"></HeaderStyle>
                    <ItemStyle ForeColor="Gray"></ItemStyle>
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="FirstName" HeaderText="FIRST NAME" DataField="FirstName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="LastName" HeaderText="LAST NAME" DataField="LastName">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Position" HeaderText="POSITION" DataField="Position">
                </telerik:GridBoundColumn>
                <telerik:GridDateTimeColumn UniqueName="DOB" HeaderText="DOB" DataField="DOB" DataType="System.DateTime" DataFormatString="{0:dd-MMM-yyyy}">
                </telerik:GridDateTimeColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
                        style="border-collapse: collapse;">
                        <tr class="EditFormHeader">
                            <td colspan="2" style="font-size: small">
                                <b>Employee Details</b>
                            </td>
                        </tr>
                        <tr>
                            <td>Id:
                            </td>
                            <td>
                                <telerik:RadTextBox ID="txtId" Text='<%# Bind( "Id") %>' runat="server" TabIndex="1" Skin="Black">
                                </telerik:RadTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>FirstName:
                            </td>
                            <td>
                                <telerik:RadTextBox ID="txtFirstName" Text='<%# Bind( "FirstName") %>' runat="server" TabIndex="2" Skin="Black">
                                </telerik:RadTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Last Name:
                            </td>
                            <td>
                                <telerik:RadTextBox ID="txtLastName" Text='<%# Bind( "LastName") %>' runat="server" TabIndex="3" Skin="Black">
                                </telerik:RadTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Title:
                            </td>
                            <td>
                                <telerik:RadTextBox ID="txtPosition" Text='<%# Bind( "Position") %>' runat="server" TabIndex="4" Skin="Black">
                                </telerik:RadTextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>DOB:
                            </td>
                            <td>
                                <telerik:RadDatePicker ID="DOB" DbSelectedDate='<%# Bind("DOB") %>' Width="100px" runat="server" TabIndex="5" Skin="Black">
                                </telerik:RadDatePicker>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" colspan="2">
                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button
                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                    CommandName="Cancel"></asp:Button>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
</asp:Panel>
<telerik:RadWindowManager ID="Demo_Window" Skin="Black" runat="server" />


And this is the controls' cs code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
 
namespace Example.ControlTemplates.Example
{
    public partial class emp : UserControl
    {
        private DataTable dt;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string[] dateValues = { "01/08/2001", "01/08/2002", "01/08/2003", "01/08/2004", "01/08/2005" };
 
            dt = new DataTable();
            dt.Columns.Add("Id", typeof(string));
            dt.Columns.Add("FirstName", typeof(string));
            dt.Columns.Add("LastName", typeof(string));
            dt.Columns.Add("Position", typeof(string));
            dt.Columns.Add("DOB", typeof(DateTime));
 
            dt.Rows.Add(25, "Indocin", "David", "Manager", Convert.ToDateTime(dateValues[0]));
            dt.Rows.Add(50, "Enebrel", "Sam", "Foreman", Convert.ToDateTime(dateValues[1]));
            dt.Rows.Add(10, "Hydralazine", "Christoff", "Sales Person", Convert.ToDateTime(dateValues[2]));
            dt.Rows.Add(21, "Combivent", "Janet", "Clerk", Convert.ToDateTime(dateValues[3]));
            dt.Rows.Add(100, "Dilantin", "Melanie", "Store Keeper", Convert.ToDateTime(dateValues[4]));
        }
 
        public DataTable getEmpData()
        {
 
 
            return dt;
 
        }
 
        protected void DemoGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
 
            DemoGrid.DataSource = getEmpData();
        }
 
        protected void DemoGrid_ItemInsert(object sender, GridCommandEventArgs e)
        {
 
            var InsertableItem = ((GridEditFormInsertItem)e.Item);
            GridEditFormItem formItem = e.Item as GridEditFormItem;
 
            RadTextBox txtId = (RadTextBox)formItem.FindControl("txtId");
            RadTextBox txtFN = (RadTextBox)formItem.FindControl("txtFirstName");
            RadTextBox txtLN = (RadTextBox)formItem.FindControl("txtLastName");
            RadTextBox txtP = (RadTextBox)formItem.FindControl("txtPosition");
            RadDatePicker dob = (RadDatePicker)formItem.FindControl("DOB");
 
            DataRow row = dt.NewRow();
            dt.Rows.Add(row);
 
            if (string.IsNullOrEmpty(txtId.Text))
            {
                Demo_Window.RadAlert("Id Cannot be Empty...", 330, 180, "Warning", "");
                e.Canceled = true;
            }
            else
                row["Id"] = txtId.Text;
 
 
            if (string.IsNullOrEmpty(txtFN.Text))
            {
                Demo_Window.RadAlert("FirstName Cannot be Empty...", 330, 180, "Warning", "");
                e.Canceled = true;
            }
            else
                row["FirstName"] = txtFN.Text;
 
            if (string.IsNullOrEmpty(txtLN.Text))
            {
                Demo_Window.RadAlert("LastName Cannot be Empty...", 330, 180, "Warning", "");
                e.Canceled = true;
            }
            else
                row["LastName"] = txtLN.Text;
 
            if (string.IsNullOrEmpty(txtP.Text))
            {
                Demo_Window.RadAlert("Position Cannot be Empty...", 330, 180, "Warning", "");
                e.Canceled = true;
            }
            else
                row["Position"] = txtP.Text;
 
            if (!dob.SelectedDate.HasValue)
            {
                Demo_Window.RadAlert("Choose DOB...", 330, 180, "Warning", "");
                e.Canceled = true;
            }
            else
                row["DOB"] = dob.DbSelectedDate;
 
 
            dt.AcceptChanges();
 
 
        }
 
        protected void DemoGrid_ItemUpdate(object sender, GridCommandEventArgs e)
        {
 
            var editableItem = ((GridEditableItem)e.Item);
            string id = editableItem.GetDataKeyValue("Id").ToString();
            GridEditFormItem formItem = e.Item as GridEditFormItem;
 
            RadTextBox txtFN = (RadTextBox)formItem.FindControl("txtFirstName");
            RadTextBox txtLN = (RadTextBox)formItem.FindControl("txtLastName");
            RadTextBox txtP = (RadTextBox)formItem.FindControl("txtPosition");
            RadDatePicker dob = (RadDatePicker)formItem.FindControl("DOB");
 
 
            DataRow row = dt.Rows.Cast<DataRow>().Where(r => r["Id"].ToString() == id).Single();
            if (row["Id"].ToString() == id)
            {
                if (string.IsNullOrEmpty(txtFN.Text))
                {
                    Demo_Window.RadAlert("FirstName Cannot be Empty...", 330, 180, "Warning", "");
                    e.Canceled = true;
                }
                else
                    row["FirstName"] = txtFN.Text;
 
                if (string.IsNullOrEmpty(txtLN.Text))
                {
                    Demo_Window.RadAlert("LastName Cannot be Empty...", 330, 180, "Warning", "");
                    e.Canceled = true;
                }
                else
                    row["LastName"] = txtLN.Text;
 
                if (string.IsNullOrEmpty(txtP.Text))
                {
                    Demo_Window.RadAlert("Position Cannot be Empty...", 330, 180, "Warning", "");
                    e.Canceled = true;
                }
                else
                    row["Position"] = txtP.Text;
 
                if (!dob.SelectedDate.HasValue)
                {
                    Demo_Window.RadAlert("Choose DOB...", 330, 180, "Warning", "");
                    e.Canceled = true;
                }
                else
                    row["DOB"] = dob.DbSelectedDate;
 
                dt.AcceptChanges();
 
            }
 
 
        }
 
    }
}




Thank you for your help,
Hans










0
Maria Ilieva
Telerik team
answered on 16 Jan 2014, 12:41 PM
Hello Hans,

In case the previously provided approach does not help i would suggest you to try placing the Ajax  settings in the CreateChildControls event like this:
public class VisualWebPart1 : WebPart
{

RadAjaxManager ajaxmgr;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ajaxmgr = RadAjaxManager.GetCurrent(Page);
if (ajaxmgr == null)
{
ajaxmgr = new RadAjaxManager();
Page.Items.Add(typeof(RadAjaxManager), ajaxmgr);
}
 
if (Page.Form != null)
{
Page.Form.Controls.AddAt(0, ajaxmgr);
}
EnsureChildControls();
}
 
protected override void CreateChildControls()
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
p = control.FindControl("DemoPanel") as Panel;
lp = control.FindControl("Demo_LoadingPanel") as RadAjaxLoadingPanel;
//Find more controls to add to the ajax settings
if (ajaxmgr != null)
{
ajaxmgr.AjaxSettings.AddAjaxSetting(p, p, lp);
}
 
}
}

Also please make sure that you are adding the user control to the web part before trying to access the needed controls.



Regards,
Maria Ilieva
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 the blog feed now.
0
Hans
Top achievements
Rank 1
answered on 23 Jan 2014, 04:07 AM
Hi Maria,

Still it is not working and I really need this done. I cannot wait months to be done through messages. Unfortunately , you response is too long for someone who is working in a production environment and have deadlines.
I want to send you the demo I done
If I need to pay something, I will pay but I want the demo to be fixed.

Please let me know asap how we can do this.

Regards,
Mihai
0
Maria Ilieva
Telerik team
answered on 23 Jan 2014, 03:16 PM
Hi Hans,

I completely understand the urgency of this case and will suggest you as a licensed user to open a regular support ticket where the project could be attached. As soon as we have runnable version of your application we will do our best to debug the issue locally and provide proper solution.

Regards,
Maria Ilieva
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 the blog feed now.
Tags
Ajax
Asked by
Hans
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Hans
Top achievements
Rank 1
Share this question
or