0
votes

I am creating Tridion GUI Extension, in this i have created a button ("InsertCP") in the Ribbon toolbar. The scenario is:

1.User selects any text from the Rich Text Box of the component
2.User clicks the "InsertCP" button from the ribbon toolbar.
3.when the user clicks the button , i am opening my custom aspx page.
4.From the custom aspx page, user can select "Component" and "Component Template".
5.I am storing the selected component and component template tcm id in a variable.
6.I have submit button in the custom aspx page.
7.when the user clicks the submit button, i need to format the selected text as below in the Rich Text box source.

Ex:

<a href="componentid=tcm-00-000, componenttemplateid="tcm-00-000-00">Selected Text</a>

I have done upto the step 6, i am tryng the step 7, when i click the submit button am not able to submit the selected ID.

I am getting these error when i am adding tridion control in my aspx page

My ASPX page:

<html xmlns="http://www.w3.org/1999/xhtml"     xmlns:c="http://www.sdltridion.com/web/ui/controls"> 
<head runat="server">
<title></title>
<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> 
</head>

<div>
    <asp:TextBox ID="txttags" runat="server" Width="800px"      ></asp:TextBox>       
    <asp:Button ID="btnsubmit" runat="server" Text="Submit"     onclick="btnsubmit_Click"  /> 

         <c:button id="InsertButton" runat="server" class="customButton greybutton" label="Insert" />         
</div>

Cs code :

protected void btnsubmit_Click(object sender, EventArgs e)
    {
txttags.Text = "anyvalue.";
}

and java script are same as exiting one.. But i am getting error on runtime.Do i need to add any namespace in cs page.

My CS page will have so many events like below.Cant i use tridion control button for this page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tridion.ContentManager.CoreService.Client;
using System.Xml.Linq;
using System.Xml;


namespace Somename
{

public partial class Classname
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void ddSelectOption_SelectedIndexChanged(object sender, EventArgs e)
    {



    }


    protected void lbPublication_SelectedIndexChanged(object sender, EventArgs e)
    {

    }


    protected void lbPubFolders_SelectedIndexChanged(object sender, EventArgs e)
    {


    }


    protected void lbComponent_SelectedIndexChanged(object sender, EventArgs e)
    {

    }


    protected void lbComponentTemplate_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
2
your example of the selected text is a bit unclear, perhaps you can put some more detail in it, what exactly needs to be done with it? - Bart Koopman
i need to create a tag like what i have shown .Please look into updated question - SDLBeginner

2 Answers

1
votes

Looking at your update I gather what you want is to create an anchor element based on the information from your ASPX page into the selected text of the Rich Text field of the Component.

To build something like that you can best look at something similar which is available. Simplest example I can think of is the Hyperlink button in the Format ribbon toolbar. That consists of two items:

  1. ..\Tridion\WebUI\Editors\CME\Views\Popups\Link\Link.aspx
  2. ..\Tridion\WebUI\Editors\CME\Views\Popups\Link\Link.js

The magic all happens inside the JavaScript file (as usually is done in these UI extensions). In the initialize() method, the selected part is extracted like so:

var p = this.properties;
var c = p.controls;

// Get selected acronym
p.OldLink = (window.dialogArguments && window.dialogArguments.link) ? window.dialogArguments.link : {};

The post back to the Rich text field is done in the _onOkButtonClicked(event) method like so:

this._buildNewLinkHtml();
this.fireEvent("submit", { link: this.properties.NewLink });
window.close();

You can take a closer look at the rest of the code in the Link.js file and rebuild it to suit your needs.

By the way, looking at the info you want to post back in the href, I would say its easier if you format it a bit more according to some sort of standard, you could for instance place your URIs there like JSON:

<a href="{'component'='tcm:1-23','componenttemplate'='tcm:1-45-32'}">text</a>

Or possibly even abuse the title attribute for your Component Template URI:

<a href="tcm:1-23" title="tcm:1-45-32">text</a>

Since I'm assuming your Component Template code will use these values to do something special with this hyperlink construct.

Edit

The unrecognized tag prefix c error you show in the added image, you can solve by adding the correct namespace reference as I indicated in my answer here. So just add it in your HTML element:

<html xmlns:c="http://www.sdltridion.com/web/ui/controls" xmlns="http://www.w3.org/1999/xhtml"> 

As for the unrecognized cc tag prefix, you shouldn't need to bother with that one, it seems to be resolved at runtime just fine since you are running this inside the Tridion context.

1
votes

I'll provide a second answer to your updated question, although you are still keeping us a bit in the dark since you only mention you get a runtime error and not what that exactly is (it is impossible for me to provide a good answer if I don't know what error you get).

Your ASPX page should look something like this:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Example.MyPopup" ClassName="MyPopup" %>
<%@ Import Namespace="Tridion.Web.UI" %>
<%@ Register TagPrefix="ui" Namespace="Tridion.Web.UI.Editors.CME.Controls" Assembly="Tridion.Web.UI.Editors.CME" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="MyPopup" class="tridion popup" xmlns:c="http://www.sdltridion.com/web/ui/controls" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>My Popup Example</title>
        <cc:TridionManager runat="server" Editor="ExampleEditor" IsStandAloneView="false">
            <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>
    </head>
    <body>
        <table id="tblHeight" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td id="InputField" valign="top">
                    <table>
                        <tr>
                            <td id="NameLabelCell" nowrap="nowrap">My Label</td>
                            <td><input id="txttags" name="txttags" value="" tabindex="1" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr id="FooterRow">
                <td class="footer" align="right">
                    <div class="BtnWrapper">
                        <c:Button ID="BtnOk" runat="server" TabIndex="2" Label="<%$ Resources: Tridion.Web.UI.Strings, OK %>" />
                        <c:Button ID="BtnCancel" runat="server" TabIndex="3" Label="<%$ Resources: Tridion.Web.UI.Strings, Cancel %>" />
                    </div>
                </td>
            </tr>
        </table>
    </body>
</html>

Note: the table markup is copied directly from the Anchor popup, feel free to use divs instead and style them any way you want, the example is meant to show you how to reuse the existing Tridion controls Your CS would then become:

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 Example
{
    [ControlResources("Example.MyPopup")]
    public class MyPopup : PopupView
    {
    }
}

It doesn't contain anything, and it doesn't need to, as all the actions you will be doing in your JavaScript as explained before.