Saturday 22 February 2014

How to Create Custom data type in umbraco using usercontrol.?

How to Create Custom data type in umbraco using usercontrol.?

Umbraco provide interface for create custom data type.
Umbraco Interface:  umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
Reference Dll : umbraco.editorControl
In Interface: Umbraco has created Property which will used to store value it’s manage by umbraco so no need to give much attention here.
The code Part in .Net:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.editorControls;
using umbraco.cms.businesslogic.web;
 
namespace UmbracoCustomDataTypes.usercontrols
{
    public partial class CustomFontDropDown : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
 
        public object value
        {
            get
            {
                return drop1.SelectedValue;
            }
            set
            {
                drop1.SelectedValue = value.ToString();
            }
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
 
            }
        }
 
        protected void Button1_Click(object sender, EventArgs e)
        {
            string dropDownValue = string.Empty;
            dropDownValue = value.ToString();
            Label1.Text =  "You have selected this"+ dropDownValue;
        }
    }
}
Explanation:CustomFontDropDown inherit umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
interface and umbraco Interface containing property value which has type object. Here CustomFontDropDown class will set Umbraco interface value.
CustomFontDropDown.ascx File
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomFontDropDown.ascx.cs" Inherits="UmbracoCustomDataTypes.usercontrols.CustomFontDropDown"%>
<asp:DropDownList id="drop1" runat="server">
    <asp:ListItem>Item 1</asp:ListItem>
    <asp:ListItem>Item 2</asp:ListItem>
    <asp:ListItem>Item 3</asp:ListItem>
    <asp:ListItem>Item 4</asp:ListItem>
    <asp:ListItem>Item 5</asp:ListItem>
    <asp:ListItem>Item 6</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Sample:Click Here


No comments:

Post a Comment