How to access Tridion controls in code behind?

坚强是说给别人听的谎言 提交于 2019-12-24 08:10:11

问题


I am customizing the Tridion ribbon toolbar to add a button. How can I access Tridion controls like button and dropdown inside my .NET ASPX page?


回答1:


This post may help you http://www.tridiondeveloper.com/ribbon-item-group

Although I believe the output of any ASPX or ASCX which is stored in an Editor itself is cached, so the preferred method of creating CM functionality is to use JavaScript and background services stored in a Model, You may want to look at the open source PowerTools project for some more ideas (http://code.google.com/p/tridion-2011-power-tools/).




回答2:


Your question is a bit vague on what exactly you are trying to accomplish, to add a button to the ribbon toolbar you wouldn't need an ASPX page.

But if your ribbon button is opening a popup window in which you want to use Tridion Controls you will have to start with importing the Tridion.Web.UI namespaces.

in your ASPX page you can add:

<%@ Import Namespace="Tridion.Web.UI" %>
<%@ Register TagPrefix="ui" Namespace="Tridion.Web.UI.Editors.CME.Controls" Assembly="Tridion.Web.UI.Editors.CME" %>

In the head of your ASPX page you should mention the tridion manager control:

<cc:tridionmanager runat="server" editor="ExampleEditor" isstandaloneview="true">
    <dependencies runat="server">       
        <dependency runat="server">Tridion.Web.UI.Editors.CME</dependency>
        <dependency runat="server">Tridion.Web.UI.Editors.CME.Controls</dependency>
    </dependencies>
</cc:tridionmanager>

And then you can use the controls in your page. Be sure not to forget the namespace reference

xmlns:c="http://www.sdltridion.com/web/ui/controls"

Your code behind you should then extend from a Tridion View, for instance the Tridion.Web.UI.Editors.CME.Views.Popups.PopupView

using Tridion.Web.UI.Core;
using Tridion.Web.UI.Controls;
using Tridion.Web.UI.Core.Controls;
using Tridion.Web.UI.Editors.CME.Views.Popups;

namespace Extensions.Example.Views
{
    [ControlResources("Extensions.Example.Views.ExampleDialog")]
    [ControlResourcesDependency(typeof(Stack))]
    public class ExampleDialog : PopupView
    {
    }
}

It is all possible but not sure about the support level on reusing the Tridion controls. They are not part of a public API for as far as I know and also nothing from it is documented anywhere (you can look at the ASPX pages in the ..\Tridion\web\WebUI\Editors\CME\Views directory, but you have no examples for the code behind stuff which mostly isn't there anyways). So I would actually recommend you, not to reuse the existing controls and in your ASPX page if you want to use .NET here. In that case just use your own controls. If those controls would need access to the Tridion CMS, you should have them use the core service for that.

It is of course possible to just use the Tridion controls in combination with the JavaScript API as is shown in the existing views. If you use a c:Button control on your page, in the JavaScript code you can access it as follows:

var p = this.properties;
var c = p.controls;
c.BtnExmpl = $controls.getControl($("#BtnID"), "Tridion.Controls.Button");

// add an event handler like this
$evt.addEventHandler(c.BtnExmpl, "click", this.getDelegate(this._onExmplClicked));


来源:https://stackoverflow.com/questions/9890099/how-to-access-tridion-controls-in-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!