If you simply attach the attribute DCPlugin to any User Control and set the "Url" property to point to the correct .ascx, if will automatically register a Dynamic Content element pointing to that User Control, and expose any public property on the User Control as Dynamic Content Properties, if they are any of the following types: PropertyData, String, Int32, Boolean, PageReference.
This lets you easily turn existing user controls in your site into placable and customizable objects that can be used anywhere.

Example
    [DCPlugin(DisplayName = "QuickSearch", Description = "A Quick Search Box", Url = "~/Templates/Public/Units/Static/QuickSearch.ascx")]
    public partial class QuickSearch : UserControlBase
    {
        private static string _searchUrl = "{0}&quicksearchquery={1}";
        private string _searchPageUrl;

        public string StartText
        {
            get
            {
                return SearchText.Text;
            }
            set
            {
                SearchText.Text = value;
            }
        }

        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
        }
	    
        /// <summary>
        /// Redirects to the search result page
        /// </summary>
        protected void Search_Click(object sender, EventArgs e)
        {
            if(SearchPageUrl == null)
            {
                return;
            }
            string searchText = Server.UrlEncode(SearchText.Text.Trim());
            Response.Redirect(string.Format(_searchUrl, SearchPageUrl, searchText));
        }

        /// <summary>
        /// Gets or sets the search page url
        /// </summary>
        /// <remarks>By default the search page url is intialized using the dynamic 
        /// property SearchPage which should point to the PageReference of the search page</remarks>
        public string SearchPageUrl
        {
            get
            {
                if(_searchPageUrl == null)
                {
                	PageReference searchPageRef = CurrentPage["SearchPage"] as PageReference;
                	if (searchPageRef != null) 
                	{
                    	PageData searchPage = GetPage(searchPageRef);
                    	_searchPageUrl = searchPage.LinkURL;
                	}
                }
                return _searchPageUrl;
            }
            set { _searchPageUrl = value; }
        }
    }

Last edited Oct 23, 2009 at 11:12 PM by AllanThraen, version 1

Comments

No comments yet.