bookpublisher.cs

来自「一个ASP.NET下的中文内容管理和社区系统」· CS 代码 · 共 95 行

CS
95
字号
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
	using ASPNET.StarterKit.Communities.Books;



    //*********************************************************************
    //
    // BookPublisher Class
    //
    // Represents a book publisher
    //
    //*********************************************************************
	[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
	public class BookPublisher : WebControl {

        private string _text = String.Empty;
        private string _link = String.Empty;
        
    
        //*********************************************************************
        //
        // BookPublisher Constructor
        //
        // Assign a default css style (the user can override)
        //
        //*********************************************************************
        public BookPublisher() : base() {
            CssClass = "bookPublisher";

            // Get ContentInfo object
			if (Context != null) {
				BookInfo objBookInfo = (BookInfo)Context.Items["ContentInfo"];
			    _text = objBookInfo.Publisher;
			    _link = objBookInfo.PublisherLink;
			}
		}

    

        //*********************************************************************
        //
        // TagKey Property
        //
        // Only display a link if publisherLink has value
        //
        //*********************************************************************

        override protected HtmlTextWriterTag TagKey {
            get {
                if (_link == String.Empty)
                    return HtmlTextWriterTag.Span;
                else
                    return HtmlTextWriterTag.A;
            }
        }


        //*********************************************************************
        //
        // AddAttributesToRender Method
        //
        // Add the HRef that links to the publisher
        //
        //*********************************************************************
        protected override void AddAttributesToRender(HtmlTextWriter writer) {
            if (_link != String.Empty) {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, _link);
                writer.AddAttribute(HtmlTextWriterAttribute.Target, "_blank");
                base.AddAttributesToRender(writer);
            }
        }        


    
        //*********************************************************************
        //
        // RenderContents Method
        //
        // Display the title
        // Note: we are going to HTML Encode here to prevent script injections
        //
        //*********************************************************************
        override protected void RenderContents(HtmlTextWriter writer) {
			writer.Write(HttpUtility.HtmlEncode(_text));    
        }


    }
}

⌨️ 快捷键说明

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