Ektron 9.00
Working with Ektron Server Controls
Developers use Microsoft Visual Studio to work with Ektron server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified.s.
You can drag and drop a server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified. onto an ASPX page to coexist with other components. This includes control for almost everything from content, to user management, breadcrumbs, and social network controls—to provide out-of-the-box markup and functionality. In addition to having a set of properties that you can use to change the controls' output and behavior, you can access the server control APIApplication Programming Interface. The Server Control Reference describes the Ektron server controls.
Ektron’s server controls let you insert many standard methods and properties within the Visual Studio environment. This means that you can see the effect of your changes in real time—you do not have to modify a page then compile a sample project to see the results.
You can insert server controls using drag and drop or programmatically. You can also use databinding to retrieve and display data from Ektron.
Additional information and examples for Ektron server controls are available online after you install the following sample site.
http://localhost/samplesite/Default.aspx
Replace localhost
with the webroot
where you installed the sample site.
IMPORTANT: For improved security,you should rename or remove the Web services file when you move it to your production server. After installation, this file is named ServerControlWS.asmx
in the /siteroot/Workarea/
folder in your Web root.
ServerControlWS.asmx
is the Web service that lets server controls communicate with Ektron. The path is coded in the web.config
file as follows. Edit this line if you change the location or name of the ServerControlWS.asmx
file.
<!-- Web Service URL for Server Controls design time -->
<add key="WSPath"
value="http://localhost/siteroot/Workarea/ServerControlWS.asmx" />
This section describes how to install server controls (except for Search Server controls, which are found at Adding Search Server Controls to Visual Studio).
NOTE: You must copy the dlls to a local drive before installing them. You cannot install them from a network drive.
Ektron
‘s dll files (siteroot/bin
). siteroot/bin/Ektron.Cms.Controls.dll
file and click Open. This file provides access to Ektron’s server controls.NOTE: Using the bin folder in your site provides better speed when loading Web pages. However, if you use the bin folder located in C:\Program Files\CMS400vxx\bin
, you do not have to worry about deleting the .dll file if you change or delete your site. The file is identical in both places.
siteroot/bin/Ektron.Cms.Framework.UI.Controls.EktronUI.dll
. The controls appear on the Toolbox tab.For easier viewing once the server controls are installed, you can right click on them and select Sort Items Alphabetically. You can only see the server controls when an ASPX template is selected.
NOTE: If you want to delete all of the server controls from the Ektron Server Control tab, right click on the tab and choose Delete Tab.
localhost/siteroot/projectname.sln
. For example, for the OnTrek sample site, the file is OnTrek.sln
. The sample site project opens.When you select a page, its properties appear in the Properties Window, and the page appears in the center of the screen. A control’s properties include several standard .NET properties along with Ektron-specific ones. The Ektron properties are labeled as illustrated below.
After you open the solution file in Visual Studio and add the required files, build the project. After the project is built, a browser opens and it appears as a Web page. You can also view a Web page while working on it by right clicking on the Web form and clicking View in Browser.
CMS Explorer lets you browse your website to identify Ektron objects such as folders, calendars, blogs, and content blocks. You access the CMS Explorer from the Properties window. For example, if you insert a ListSummary server control, its FolderID
property identifies the folder whose contents are displayed.
NOTE: You cannot be logged into the CMS Explorer and the Workarea at the same time. If you log into the CMS Explorer while logged into the Workarea, an error message appears. If you log into the Workarea while logged into the CMS Explorer, you will need to re-login to the CMS Explorer when you return to using it.
NOTE: Although you see the object in the selected language in Visual Studio, the language is not stored. For example, if you select a German content block whose ID=2, Ektron only stores content block ID=2
. When a visitor to your site browses to that page, the content block does not appear in the selected language. Instead, it is determined by a cookie or the user’s language selection.
Because Visual Studio is a visual environment, you can watch the page layout change as you add or move a control and adjust its properties. Use the CMS Explorer whenever you need to identify an Ektron object (such as content block or collectionA list of Ektron content links for display on a Web page.).
You can manipulate a server control after dragging and dropping it on a Web form by using the code-behind. The following example shows using a drag and drop ListSummary server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified. then modifying it programmatically.
Dim myString As String Dim i For i = LBound(ListSummary1.EkItems)To UBound(ListSummary1.EkItems) myString &= "<a href=""" & ListSummary1.EkItems(i).QuickLink & """>" & ListSummary1.EkItems(i).DateCreated & "</a><br>" ListSummary1.Text = myString Next
ListSummary1 is the ID of the object. It is used to get access to its properties.
Dim myString As String
Text property to that string.
myString &= "<a href=""" & ListSummary1.EkItems(i).QuickLink & """>" & ListSummary1.EkItems(i).DateCreated & "</a><br>"
Dim i For i = LBound(ListSummary1.EkItems) To UBound(ListSummary1.EkItems) Next
This example outputs the date created for each content block in a ListSummary.
You may want to insert server controls programmatically for the following reasons:
To insert an Ektron server control programmatically:
NOTE: You do not need to declare a namespace. However if you do not, you must fully qualify objects that you create. For any customization of Ektron, classes or controls that inherit from Ektron classes, you should create your own namespace within 'Ektron.Cms.Custom'. For example, if your company is 'AcmeExampleTech, Inc.' you should create all of your custom classes within the namespace 'Ektron.Cms.Custom.AcmeExampleTech'.
MyColl
.Ektron.Cms.Controls.Collection MyColl = new Ektron.Cms.Controls.Collection();
You can declare any server control as an object by using the server control name. See Working with Ektron Server Controls. Another example would be: Dim MyMdl as New MetaDataList.
Dim MyColl as New Collection MyColl.DefaultCollectionID = 4 MyColl.Page = Page
For descriptions of the properties and how to use them, see Accessing Server Control Properties in Code-behind Programmatically.
With C#, use this syntax.
> Ektron.Cms.Controls.Collection MyColl = new Ektron.Cms.Controls.Collection(); MyColl.DefaultCollectionID = 4; MyColl.ID = “Collection1”; MyColl.Page = Page;
These lines tell the page to display CollectionID 1 unless otherwise specified.
IMPORTANT: When using code-behind to add a server control to your Web form, you must set the Page object for the server control to Page. For example, Mycoll.Page = Page
This line needs to appear between Dim new server control line and the Fill() line. This line is not added when dragging and dropping a server control on a Web form. See Also: Referencing a Parent Page.
If you do not know an object’s ID number, you can switch to Design mode, drag and drop the object, then use the CMS Explorer to find the ID number. (See Browsing Your Ektron Site Using CMS Explorer.) If you do this, remember to delete the dropped object when you are done. You can also obtain the ID number via the Workarea. This line sets the Random
property to true.
Dim MyColl as New Collection
MyColl.ID = “Collection1”
MyColl.DefaultCollectionID = 4
MyColl.Page = Page
MyColl.Random = True
> Dim MyColl as New Collection MyColl.ID = “Collection1" MyColl.DefaultCollectionID = 4 MyColl.Page = Page MyColl.Random = True MyColl.Fill()
NOTE: Before adding this line you need to drag and drop a label on your Web form.
> Dim MyColl as New Collection MyColl.ID = “Collection1” MyColl.DefaultCollectionID = 4 MyColl.Page = Page MyColl.Random = True MyColl.Fill() Label1.Text = myColl.EkItems(0).Title
To display all items in a collection, use this syntax.
Dim myColl As New Ektron.Cms.Controls.Collection Dim ekitem As New Ektron.Cms.Common.ContentBase MyColl.DefaultCollectionID = 2 MyColl.ID = “Collection1” MyColl.Page = Page MyColl.Fill() Label1.Text = "<ul>" For Each ekitem In myColl.EkItems Label1.Text &= "<li><a href=""" & ekitem.QuickLink & """>" & ekitem.Title & "</a>" Next Label1.Text &= "</ul>"
This example displays the quick link for every content block in the collection, formatted as a bulleted list. You can use similar code to display a List Summary or search results. The following explains the new (red) code above.
label1.Text = "<ul>"
displays the opening tag for the bulleted listFor Each ekitem In myColl.EkItems
creates a loop for all content blocks in the collectionlabel1.Text &= "<li><a href=" & ekitem.QuickLink & ">" & ekitem.Title & "</a></li>"
for each content block in the collection, displays its quicklink and titleNext
loops through all content blocks in the collectionlabel1.Text &= "</ul>"
closes the bulleted listEvery server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified. has properties associated with it that you can access only programmatically. This section explains what they are, how to access them, and how to use them.
You can use Visual Studio’s intellisense feature to display a control’s properties. The intellisense box appears as soon as you insert the period (.) after the object, as illustrated below.
The intellisense box displays all properties that can be applied.
The property’s tooltip text indicates its type. In the previous example, note that the DefaultCollectionID
’s type is integer.
To learn about native Visual Studio properties, see the Visual Studio documentation. For more information about accessing Ektron object properties, see Customizing a Server Control in the code-behind.
Every server controla server control uses API language to interact with the CMS and Framework UI to display the output. A server control can be dragged and dropped onto a Web form and then modified. has the following read-only properties in the code-behind that let you personalize any page with user names and IDs, and show if they are logged in.
NOTE: The properties do not display values within Visual Studio during design time. Instead, they only display values at run time, which are dependent on the user’s login status.
Tells if a user is logged in to Ektron.
Gets the Ektron user name to display.
Gets the Ektron ID of the user to display.
The following example shows these properties in code-behind.
NOTE: You must be logged in to Ektron for this example to show your name and ID.
Literal1.Text = ContentBlock1.IsLoggedIn If ContentBlock1.IsLoggedIn Then Literal2.Text = ContentBlock1.loggedInUserName & " is logged in " Literal3.Text = ContentBlock1.loggedInUserID & " is the User ID " End If
Ektron provides access to additional properties for the following objects.
You can use intellisense to select from a list of additional object properties.
To access additional properties, use the standard property's syntax but add .ekitem
or .ekitems
after the object.
Ektron.Cms.Common.ContentBase
Ektron.Cms.Common.ContentBase
dim MyCB as New ContentBlock
MyCB.DefaultContentID = 30
MyCB.ID = “ContentBlock1”
MyCB.Page = Page
MyCB.Fill()
label1.text = MyCB.EkItem.dateCreated
or
dim MyCB as new Ektron.Cms.Controls.ContentBlock MyCB.DefaultContentID = 30 MyCB.ID = “ContentBlock1” MyCB.Page = Page MyCB.Fill() label1.text = MyCB.EkItem.dateCreated
IMPORTANT: To access additional properties for the Collection, ListSummary, and Search objects, use ekitems, not ekitem. For example: MyColl.ekitems(0).dateCreated
. where (0) is the index of the array.See Also: Accessing Items in an Array.
NOTE: The following properties are read-only. For example, you can get a content block’s ID and pass it to another part of the code. However, you cannot set a content block ID to be shown.
For example, mycb.Ekitem.id = 8
does not set a content block’s ID. To set a content block's ID, use DefaultContentID = 8
.
<a href>
tags.To access and manipulate content blocks returned by an object, use the common class Ektron.Cms.Common.ContentBase
. For example, Search, Collection and ListSummary have EkItems
(an array of ContentBase), while ContentBlock has a single EkItem
. This example creates a bulleted list of every item in the collection.
dim MyC as new Ektron.Cms.Controls.Collection MyC.DefaultCollectionID = 1 MyC.ID = “Collection1” MyC.Page = Page MyC.Fill() dim item as Ektron.Cms.Common.ContentBase MyC.Text = "<ul>" for each item in MyC.EkItems MyC.Text &= "<li>" & item.Title & "</li>" next MyC.Text &= "</ul>" Response.Write(MyC.Text())
NOTE: For information on using ekitems
with eCommerce server controls, see Using the Cart Server Control.
Server controls require a reference to their parent page (for example, using the DynamicParameter
property on a content block to check for a query string). You must provide access to the page object if you declared your control in the code-behind. To do this, set the control's Page
property to the Web page you're working on, as shown in the following example.
Ektron.Cms.Controls.Search MySearch = new Ektron.Cms.Controls.Search(); MySearch.Page = Page; MySearch.Fill();
This relationship only is required when inserting a control in the code-behind. When dragging and dropping, even if you make changes in code-behind, the relationship is automatically generated.
Best Practice
You should include the
Page
property reference when using server controls as components in the code-behind.
Visual Studio separates coding and logic from presentation. Web page formatting is handled by a page’s HTML, while the logic is handled by the code-behind, which is stored in the corresponding .vb file. For example, if the ASP.NET page is mypage.aspx
, the code-behind file is mypage.aspx.vb
.
NOTE: If you do not see the code-behind files, click Show All Files on the Visual Studio Solution Explorer toolbar (circled in the following figure).
Within the Visual Basic file, you can use Visual Basic to insert code to manipulate the events that occur on the page.
Within a Web page’s HTML, a <cms>
tag wraps the Visual Studio object. The following is an example of the Search and Contentblock server controls.
<cms:Search id="Search1" runat="server" ButtonText="Search" Display="Vertical"> </cms:Search> <cms:ContentBlock id="ctrlMainContentBlock" runat="server" DefaultContentID="1" DynamicParameter="id” OverrideXslt="Default"> </cms:ContentBlock>
Within a Visual Studio code-behind file, the Ektron server controls appear (along with the Visual Studio controls) in the Web Form Designer Generated Code section. When you click + to display this section, you see something like the following. The content block listed in HTML (from the previous section) is circled to help you see their relationship.
The next section of the code-behind page loads the page into the browser.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
You want your events to occur while the page is loading, so add the custom code following this line.
To customize an Ektron server control in the code-behind, insert code similar to the following after the Page_load command.
Dim MyObj As New Ektron.Cms.Controls.ContentBlock
This code declares a variable named MyObj
and assigns to it the value of a content block. The content block is part of the Ektron.CMS.Controls content base, so it has access to the Ektron database.
After defining MyObj as a content block, you can access its properties. For example, to assign a defaultID of 24, insert the following.
Dim MyObj As New Ektron.Cms.Controls.ContentBlock MyObj.DefaultContentID = 24
The content block can be specified dynamically in the URL of the hyperlink that calls it. If not, content block 24 displays.
This is an example of programmatically applying property values to content blocks.
If you get an Error Creating Control message while trying to use a server control, you can view the message by hovering the mouse over the control.
Best Practice
When using Ajax server controls and custom code, wrap the custom code in a check for “is not a callback,” so it is not executed when a callback from an Ajax server control occurs.
If you use an Ajax-enabled server control and write custom code, it may generate an exception, indicating the server control does not work. This issue happens during callback for the Ajax server control when custom code accesses a property that is filled during page load, but not filled during callback.
For example, a Poll server control is on a Web form, and you want the title of a content block to appear in a literal on that form. The EkItem.Title
property for the content block is filled upon page load. When a site user answers a poll question, an exception occurs during the callback because the EkItem.Title
property is not refilled. However, the site user does not see the exception because it looks like the Poll server control is not working.
The following example shows custom code that makes the content block’s title appear in the literal:
Literal1.Text = ContentBlock1.EkItem.Title
To solve this issue, wrap the custom code in a check for “is not a callback”. This prevents the code execution when callback occurs. For example:
[C#] If( !IsCallback ) { Literal1.Text = ContentBlock1.EkItem.Title } [VB] If ( Not IsCallback ) Literal1.Text = ContentBlock1.EkItem.Title End If
With data binding, you can bind Ektron server controls to a GridView Control, DataList Control, or Repeater Control. This gives more flexibility when you use data from the Ektron server controls. Benefits of data binding include ease of data manipulation and the ability to format data.
WARNING! When HTML is bound to a column, you need to add HtmlEncode = False
to it. Otherwise, the HTML appears as code. For example, <p>Ektron Inc., an innovator in Web content management software, today announced...</p>
.
The following are data bindable Ektron server controls.
The following example shows code-behind that uses a GridView to display a Collection:
NOTE: For the example code to work properly, you need to drag and drop a GridView server control on a Web form.
Dim myCol As New Ektron.Cms.Controls.Collection MyCol.ID = “Collection1”‘‘‘Create an ID for the Collection
myCol.DefaultCollectionID = 4 myCol.Page = Page
myCol.Fill()
GridView1.DataSource = myCol
GridView1.DataBind()
Steps to data binding using drag and drop server controls are as follows:
DefaultCollectionID
for the server control and make sure DisplayXslt is set to None- DataBind Only.Collection1.Fill()
For more information on GridView, DataList, Repeater and DetailsView, see the help inside Visual Studio.
High-performance, scalable Web applications store items in memory after the first time they are requested. The items include data objects, pages, and parts of a page. Caching saves and later reuses page output or application data across HTTP requests. You can store items on the Web server or other software in the request stream, such as the proxy server or browser. Caching saves time and resources because the server does not have to recreate information, particularly things that demand significant processor time or other resources. The following image contrasts data flow in non-cached and cached environments.
When a user is logged in, changes appear on the site only after time defined in the cache interval. This reduces the number of database hits, which improves your server’s performance. For example, if you add a new item to a Collection, the change only appears on the site when the cache interval expires. In the meanwhile, use Preview mode to see the updated Collection immediately.
IMPORTANT: Caching while logged in does not work with Private content. See Also: Making Content Private
To set up caching of content for a Web page:
siteroot/web.config
file’s ek_CacheControls
property’s value
to “1”
.CacheInterval
property to the number of seconds for which data should be cached. For example, to cache for 5 minutes, set CacheInterval
to 300.The default value is 0 seconds. So, you must change the default to enable caching.
The following example shows a page-level cache for non-logged-in users. You use a server control to define whether a user is logged in, then define if the page is cached, based on the user’s status.
Refresh the page. The page will cache for 20 seconds when not logged in:
Time is =
DefaultContentID = 20
.If Not ContentBlock1.IsLoggedIn Then Response.Cache.SetExpires(DateTime.Now.AddSeconds(20)) Response.Cache.SetCacheability(HttpCacheability.Public) Response.Cache.SetValidUntilExpires(True) Response.Cache.VaryByParams("id") = True
NOTE: On a PageBuilder page, you would use Response.Cache.VaryByParams("pageid") = True
.
Response.Cache.SetVaryByCustom("cmsCache")
End If Literal1.Text = Now()
NOTE: You can use the same code in a user control to cache output in a particular region of the page.
Several Ektron server controls have a CustomXml property to add custom XML to a control’s generated XML before it is processed by its XSLTExtensible Stylesheet Language Transformations. Use the CustomXml property in code-behind with these server controls:
The following examples shows a C# usage of the CustomXml property in code-behind.
protected void Page_Load(object sender, EventArgs e) { product1.CustomXml = "<banner>Save $$$ While Christmas Shopping!</banner> <specials><special><link>ProductDemo.aspx?id=1013</link> <text>A great gift for Dad!</text></special><special> <link>ProductDemo.aspx?id=1015</link><text> A great gift for Mom!</text></special></specials>"; }
The following example shows the XML sent to the XSLT file.
<root> <customXml> <banner>Save $$$ While Christmas Shopping!</banner> <specials> <special> <link>ProductDemo.aspx?id=1013</link> <text>A great gift for Dad!</text> </special> <special> <link>ProductDemo.aspx?id=1015</link> <text>A great gift for Mom!</text> </special> </specials> </customXml> </root>
This section provides background information about Microsoft’s Visual Studio. For more information, use the help feature installed with Visual Studio and Microsoft’s developer Center (Microsoft Visual Studio).
NOTE: The following definitions are from Visual Studio Help.
Grid layout is the default, which means that all controls drawn to the Web form in the designer window have absolute positioning. Here is an example.
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server"> <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 160px; POSITION: absolute; TOP: 80px" runat="server" Text="Button">
</asp:Button> <asp:Button id="Button2" style="Z-INDEX: 102; LEFT: 480px; POSITION: absolute; TOP: 88px" runat="server" Text="Button">
</asp:Button> <asp:GridView id="GridView1" style="Z-INDEX: 103; LEFT: 208px; POSITION: absolute; TOP: 152px" runat="server">
</asp:GridView>
</form>
</body>
In Grid layout, you can position your controls like a WYSIWYG editor with no knowledge of HTML. However, because absolute positioning is not rendered consistently by all browsers, the page layout can be flexible based on the size of other controls on the page, and the Web browser window.
When other controls are dynamically populated, such as a GridView, controls that appear beneath it in the Web form would be obscured if they were positioned absolutely at design time. In addition, when utilizing globalization of pages with different languages, the size of text areas can vary and cause obstructions.
The Developer Software Distribution Kit (SDKSoftware Distribution Kit) for Ektron contains the following components to help you extend and customize your site.
The API Documentation contains a detailed description of the functions included in each of the APIs. To access the Developer’s API documentation in Visual Studio, choose Help > Contents. Next, choose Ektron API Documentation from the list of contents. You can also filter the documentation so you see only Ektron’s API documentation. Click Ektron API Documentation in the filter drop-down box.
You can also access the API documentation online by clicking Ektron Developer Reference.
Extensions are developer-defined software modules that modify the behavior of Ektron.
In versions previous to Ektron version 8.0, developers used the Plug-in Extension Wizard to extend the system. As of version 8.0, Extensions are preferred over the Plug-in system.See Also: Extending CMS Behavior
Ektron controls are installed with the Developer SDK. Server controls let you insert, via drag and drop or programmatically, many standard methods and properties within the Visual Studio environment. This means that you can see the effect of your changes in real time -- you don’t have to modify a page then compile a sample project to see the results.
An opportunity to install the Developer SDK appears during the installation or upgrade of Ektron (see third checkbox from top in the following dialog box).
If Developer SDK is not checked during installation, you can install it by going to Windows Start button > All Programs > Ektron > CMS400vxx > Utilities > CMS400SDK Install.
Click on the following links for specific information about all server controls, and extended information about using server controls for user communities, eCommerce, and search.