⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemlinktitle.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Text.RegularExpressions;
	using ASPNET.StarterKit.Communities.Books;



    //*********************************************************************
    //
    // ItemLinkTitle Class
    //
    // Represents a link to a url displayed in a template
    //
    //*********************************************************************
	public class ItemLinkTitle : WebControl {

        private string _externalIconSrc = "~/Communities/Common/Images/External.gif";
    
        //*********************************************************************
        //
        // ItemLinkTitle Constructor
        //
        // Assign a default css style (the user can override)
        //
        //*********************************************************************
		public ItemLinkTitle() {
			CssClass = "itemLinkTitle";
			EnableViewState = false;
		}

    
        //*********************************************************************
        //
        // ExternalIconSrc Property
        //
        // Allows users to assign a custom icon for external links
        //
        //*********************************************************************

        public string ExternalIconSrc {
            get { return _externalIconSrc; }
            set { _externalIconSrc = value; }
        }

        //*********************************************************************
        //
        // ContentPageID Property
        //
        // Represents the contentpageID of the item
        //
        //*********************************************************************
        public int ContentPageID {
            get {
                if (ViewState["ContentPageID"] == null)
                    return -1;
                else
                    return (int)ViewState["ContentPageID"];
            }
            set { ViewState["ContentPageID"] = value; }
        }



        //*********************************************************************
        //
        // Title Property
        //
        // Represents the Title of the item
        //
        //*********************************************************************
        public string Title {
            get {
                if (ViewState["Title"] == null)
                    return String.Empty;
                else
                    return (string)ViewState["Title"];
            }
            set { ViewState["Title"] = value; }
        }



        //*********************************************************************
        //
        // Url Property
        //
        // Represents the Url of the item
        //
        //*********************************************************************
        public string Url {
            get {
                if (ViewState["Url"] == null)
                    return String.Empty;
                else
                    return (string)ViewState["Url"];
            }
            set { ViewState["Url"] = value; }
        }


    
    
        //*********************************************************************
        //
        // OnDataBinding Method
        //
        // Get the title from the container's DataItem property
        //
        //*********************************************************************
        override protected void OnDataBinding(EventArgs e) {
            ContentItem item;

            if (NamingContainer is ContentItem)
                item = (ContentItem)NamingContainer;
            else
                item = (ContentItem)NamingContainer.NamingContainer;


            LinkInfo objLinkInfo = (LinkInfo)item.DataItem;
            ContentPageID = objLinkInfo.ContentPageID;
            Title = objLinkInfo.Title;
            Url = objLinkInfo.Url;
        }


    
        //*********************************************************************
        //
        // RenderContents Method
        //
        // Display the title
        // Note: we are going to HTML Encode here to prevent script injections
        //
        //*********************************************************************
        override protected void RenderContents(HtmlTextWriter writer) {
            string _redirector = String.Format("Links_LinkRedirector.aspx?id={0}", ContentPageID);
            
			// Determine if this is an external link or not
			Regex UrlRE = new Regex("[a-zA-Z]://.+"); // matches http://something, ftp://something, etc.
			if (UrlRE.IsMatch(Url)) {
			     // add an external icon
			     if (_externalIconSrc != String.Empty)
			         writer.Write(String.Format("<img src=\"{0}\" />", Page.ResolveUrl(_externalIconSrc)));
			         
			     // create the external link
			     writer.AddAttribute(HtmlTextWriterAttribute.Href, _redirector);
			     writer.AddAttribute(HtmlTextWriterAttribute.Target, "_blank");
			     writer.RenderBeginTag(HtmlTextWriterTag.A);
			     writer.Write(HttpUtility.HtmlEncode(Title));
			     writer.RenderEndTag();    
			} else {
			     // create the external link
			     writer.AddAttribute(HtmlTextWriterAttribute.Href, _redirector);
			     writer.RenderBeginTag(HtmlTextWriterTag.A);
			     writer.Write(HttpUtility.HtmlEncode(Title));
			     writer.RenderEndTag();    
			}
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -