Sitefinity

Jump to: navigation, search
Categories » Programming » .NET Programming » ASP.NET » Sitefinity
Categories » Programming » Web Programming » ASP.NET » Sitefinity
See also: RadControls

Sitefinity CMS Online Documentation

Contents

Developing

User and Custom Controls

Ways for checking if working in admin

These are two ways for checking if a control you're working with is in the admin section. Depending on the control you might want to change how your control operates.

This way of doing is the best way to check the status if you want better control. The CmsPageMode Enum has Admin, Edit, Live, and Preview modes which give you a better idea of whats going on. The Telerik.Cms Assembly is needed for these classes

if (this.Page is CmsPageBase)
{
    CmsPageBase page = (CmsPageBase)this.Page;
    if (page.PageMode != CmsPageMode.Edit)
    {
	// run logic for when not in edit mode
    }
}

The modes for pages are below

This is a method that pretty much does the same thing but get's there in a different way. This method doesn't offer as many options but I think could be expanded to by adding more checked for urls in the logic

private bool IsPageInAdmin()
{
	// will return TRUE is the page is viewed in administration part     
	if (this.Page.Request.RawUrl.IndexOf("cmspagemode=preview") > 0)
	    return true;
	// will return TRUE is the page is in editing mode     
	if (this.Page.Request.RawUrl.IndexOf("cmspagemode=edit") > 0)
	    return true;
	// the page is viewed in the public part.     
	return false;
}

Managing Properties with Attributes

Source[1] Note: To use these attributes you should import the following namespaces:

...

Groups
[Category("List settings")]
Example:
Description Text

...

Default Property

(Attribute is set on the control class)

[DefaultProperty("PropertyID")]
Example:
Control Designers

...

Wrapping Generic Content Control

Wrapping with User Control

How to wrap a Generic Content control in 3.6 SP1

Custom Control

Implementing Simple Functionality of Custom Controls

Web Editors

Web Editors are used to create a nice GUI for your user to enter data such as the path of a page in your site or the ID of a blog entry. Here is a reference to existing ones that I found so far. You just add these as attribute on a property that you want it used for.

See also: Sitefinity Watch: Using Built-In Sitefinity WebEditors which contains more information about the following WebEditors:

Control Designers

Coming soon!

Modules

Client-Side Databinding with RadGrid and Loading Panel

<telerik:RadGrid ID="itemGrid" runat="server"
		    AutoGenerateColumns="false"
		    Skin="SitefinityItems" 
		    EnableEmbeddedSkins="false"  
		    AllowSorting="true"
		    AllowPaging="true" 
		    PageSize="50"
		    >
            <PagerStyle  Mode="NumericPages" />
            <MasterTableView CssClass="listItems listItemsBindOnClient" Width="98%">
                <Columns>
                    <telerik:GridHyperLinkColumn Text="Delete" 
                        UniqueName="Delete" DataNavigateUrlFormatString="javascript:if(confirm(\'Are you sure you want to delete this <%$Resources:EventGroup %>?\')) DeleteContent(\'{0}\')" DataNavigateUrlFields="EventGroupId">
                        <ItemStyle CssClass="gridActions delete" />
                    </telerik:GridHyperLinkColumn>                     
                    <telerik:GridHyperLinkColumn Text="Name" UniqueName="Name"  HeaderText="Name" DataTextFormatString="{0}" DataTextField="Name" DataNavigateUrlFormatString="<%= Parent.Parent.EditEventsUrl %>" DataNavigateUrlFields="EventGroupId">
                        <ItemStyle CssClass="gridActions edit"/>
                    </telerik:GridHyperLinkColumn>   
                    <telerik:GridHyperLinkColumn UniqueName="Edit"  DataTextFormatString="Edit Settings" DataNavigateUrlFormatString="<%= Parent.Parent.EditUrl %>" DataNavigateUrlFields="EventGroupId">
                        <ItemStyle CssClass="gridActions edit"/>
                    </telerik:GridHyperLinkColumn>                                                           
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <DataBinding Location="~/Sitefinity/Admin/Services/EventsService.asmx" SelectMethod="GetEventGroupsDataAndCount"  />
	            <ClientEvents OnDataBinding="RadGrid_DataBinding" OnDataBound="RadGrid_DataBound" />
            </ClientSettings>
		</telerik:RadGrid>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
 Insert javascript here
	</telerik:RadCodeBlock>
 
    <asp:PlaceHolder ID="emptyWindow" runat="server">
        <div id="empty">
            <h2 class="gridTitle"><asp:Literal ID="Literal1" runat="server" Text="No <%$Resources:EventGroups %> have been created yet."></asp:Literal></h2>
            <p><asp:HyperLink ID="createNewEmpty" runat="server" cssClass="mainLink" ToolTip="Click here to create your first <%$Resources:EventGroup %>"><strong><asp:Literal ID="Literal2" runat="server" Text="Click here to create your first <%$Resources:EventGroup %>"></asp:Literal></strong></asp:HyperLink><br />
            <%--<asp:Literal ID="Literal3" runat="server" Text="or"></asp:Literal>, <a href="#" target="_blank" title="Opens in a new browser window"><asp:Literal ID="Literal4" runat="server" Text="Check Distributors FAQ"></asp:Literal></a></p>       --%>
        </div>
    </asp:PlaceHolder>
<script type="text/javascript">
        <!--
        var dataProviderName = "<%= Parent.Parent.ProviderName %>";
        var itemGridId;
 
        function RadGrid_DataBinding(sender, args) {
 
            //Show Loading Panel
            itemGridId = "<%= itemGrid.ClientID %>";
            loadingPanel = $find("ctl00_LoadingPanelAdmin");
            if (loadingPanel != null) {
                loadingPanel.show(itemGridId);
            }
        }
 
        function RadGrid_DataBound(sender, args) {
            var itemGrid = $find("<%= itemGrid.ClientID %>");
            var count = itemGrid.get_masterTableView()._virtualItemCount;
 
            var emptyWindow = document.getElementById('empty');
            var gridPlaceholder = document.getElementById('gridPlaceholder');
            if (count > 0) {
                emptyWindow.style.display = 'none';
                gridPlaceholder.style.display = '';
            }
            else {
                emptyWindow.style.display = '';
                gridPlaceholder.style.display = 'none';
            }
 
            if (loadingPanel != null) {
                // Hide and Cleanup
                loadingPanel.hide(itemGridId);
                loadingPanel = null;
                itemGridId = null;
            }
        }
 
        function OnFailed(error) {
	        alert("Stack Trace: " + error.get_stackTrace() + "/r/n" +
		        "Error: " + error.get_message() + "/r/n" +
		        "Status Code: " + error.get_statusCode() + "/r/n" +
		        "Exception Type: " + error.get_exceptionType() + "/r/n" +
		        "Timed Out: " + error.get_timedOut());
        }
        function DeleteContent(Id) {
            ITVantage.Events.Services.EventsService.DeleteEventGroup(Id, dataProviderName, ContentChange_Success, OnFailed);
        }
 
        function ContentChange_Success(result) {
            var masterTable = $find("<%= itemGrid.ClientID %>").get_masterTableView();
            masterTable.rebind();
        }
        -->
		</script>

Mapping a control to use external template

There are certain situations where you want to map an external template to a control. In order to do that follow the blog entries here.

Extras

Message Control

The MessageControl used in the Sitefinity admin section can be used elsewhere for communicating status information to the user. [2]

In an aspx or ascx file:

<sfMsg:MessageControl runat="server" ID="messageCtrl">  
    <ItemTemplate> 
        <asp:Label runat="server" ID="messageText"></asp:Label> 
    </ItemTemplate> 
</sfMsg:MessageControl>

Note: There must be a control with ID messageText in ItemTemplate to contain the status text.

In your code, access the MessageControl as follows:

messageCtrl.Message = "Hello World!";  
messageCtrl.Mode = MessageMode.Success;


Designing

Modules

There are many styles already in the Sitefinity admin that you can use for the admin controls of any custom module controls that you make. You just need to know what to use where and that's what this section will help you with.

References

Personal tools
Namespaces
Variants
Actions
Navigation
Categories
Toolbox