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

📄 itemtitlelink.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;



    //*********************************************************************
    //
    // ItemTitleLink Class
    //
    // Represents a title displayed in a template as a link
    //
    //*********************************************************************
	[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]	
	public class ItemTitleLink : WebControl {

        private SectionInfo objSectionInfo;
    
    
        //*********************************************************************
        //
        // ItemTitle Constructor
        //
        // Assign a default css style (the user can override)
        //
        //*********************************************************************
		public ItemTitleLink() : base(HtmlTextWriterTag.A) {
			CssClass = "itemTitleLink";
			EnableViewState = false;

            if (Context != null)
                objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
		}

    
        //*********************************************************************
        //
        // 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;

            ContentInfo objContentInfo = (ContentInfo)item.DataItem;
            ViewState["ContentPageID"] = objContentInfo.ContentPageID;
            ViewState["ContentPageSectionID"] = objContentInfo.SectionID;
            ViewState["Title"] = objContentInfo.Title;
        }

        


        protected override void AddAttributesToRender(HtmlTextWriter writer) {
            string link;
            
            int contentPageSectionID = (int)ViewState["ContentPageSectionID"];
            
            // if content in current section, just link
            if (objSectionInfo.ID == contentPageSectionID)      
                link = String.Format("{0}.aspx", ViewState["ContentPageID"]);
            else
                link = ContentPageUtility.CalculateContentPath(contentPageSectionID, (int)ViewState["ContentPageID"]);
            
            writer.AddAttribute(HtmlTextWriterAttribute.Href, link);
            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(Context.Server.HtmlEncode((string)ViewState["Title"]));    
        }


    }
}

⌨️ 快捷键说明

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