Ribbon Control

CustomActions, displayed in the Ribbon Row, need to be controled using Javascript. A Framework-Component makes it possible to handle and manipulate events on the server-side without developing Javascript.

The following Example registers a callback funktion to the Click-Event of the CustomAction.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sapiens.at.SharePoint.CustomActions;
using Sapiens.at.FrameworkSample.Entities;
using System.Web.UI;
using Microsoft.SharePoint;
using Sapiens.at.SharePoint.Repositories;
using System.Text.RegularExpressions;
using Microsoft.SharePoint.Utilities;
using System.Web;

namespace Sapiens.at.FrameworkSample.CustomActions.AddEmployeeForm
    class AddEmployee : RibbonAction
        public AddEmployee()
            RegisterCommand(new CustomActionConfig("Sapiens.PageComponent.Command.AddEmployeeForm")
                IsApplicable = IsApplicable,
                //CallbackScript = "window.location.href = '../../Lists/Employees/NewForm.aspx?Source=' + encodeURIComponent(window.location.href + '?SelectedID=' + selectedId)",
                Callback = OnAddEmployeeFormClicked

        private bool IsApplicable()
            return IsApplicableListItem(new string[] { Department.ListUrl });

        private void OnAddEmployeeFormClicked(string command, Page page)
            var source = HttpUtility.UrlEncode(page.Request.QueryString["Source"] + "?SelectedID=" + SPContext.Current.ItemId);
            var url = string.Format("../../{0}?Source={1}&IsDlg=1", 
                new ListRepository(Employee.ListUrl, SPContext.Current.Web).List.Forms[PAGETYPE.PAGE_NEWFORM].Url,
            page.Response.Redirect(url, true);

Last edited Jul 6, 2011 at 12:08 PM by florianwachter, version 4


No comments yet.