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

📄 linktitle.cs

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

	[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
    public class LinkTitle : WebControl {

        private int _contentPageID;
        private string _text;
        private string _url;
        private string _externalIconSrc = "~/Communities/Common/Images/External.gif";


        //*********************************************************************
        //
        // LinkTitle Constructor
        //
        // Assign a default css style (the user can override)
        //
        //*********************************************************************
        public LinkTitle() : base() {
            CssClass = "linkTitle";

            // Get ContentInfo object
			if (Context != null) {
				LinkInfo objLinkInfo = (LinkInfo)Context.Items["ContentInfo"];
                if (objLinkInfo != null) {
                    _contentPageID = objLinkInfo.ContentPageID;
			        _url = objLinkInfo.Url;
                    _text = objLinkInfo.Title;
                }
			}
		}

    
        //*********************************************************************
        //
        // Text Property
        //
        // Used to assign text when previewing
        //
        //*********************************************************************
        public string Text {
            get { return _text; }
            set { _text = value; }
        }



    
        //*********************************************************************
        //
        // Url Property
        //
        // Used to assign a URL when previewing
        //
        //*********************************************************************
        public string Url {
            get { return _url; }
            set { _url = value; }
        }

    
        //*********************************************************************
        //
        // ExternalIconSrc Property
        //
        // Allows users to assign a custom icon for external links
        //
        //*********************************************************************
        public string ExternalIconSrc {
            get { return _externalIconSrc; }
            set { _externalIconSrc = value; }
        }


        //*********************************************************************
        //
        // 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(_text));
			     writer.RenderEndTag();    
			} else {
			     // create the external link
			     writer.AddAttribute(HtmlTextWriterAttribute.Href, _redirector);
			     writer.RenderBeginTag(HtmlTextWriterTag.A);
			     writer.Write(HttpUtility.HtmlEncode(_text));
			     writer.RenderEndTag();    
			}
        }



    }
}

⌨️ 快捷键说明

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