📄 displaytopic.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// DisplayTopic Class
//
// This control displays either a topic name or topic image that
// links to the Topic page.
//
//*********************************************************************
[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
public class DisplayTopic : WebControl {
string _name = String.Empty;
string _image = String.Empty;
bool _alwaysDisplay = false;
public DisplayTopic() : base() {
// Set CSS Class
CssClass = "displayTopic";
// Get ContentInfo from context
if (Context != null) {
Object objContentInfo = Context.Items["ContentInfo"];
if (objContentInfo != null) {
_name = ((ContentInfo)objContentInfo).TopicName;
_image = ((ContentInfo)objContentInfo).TopicImage;
}
}
}
public string Name {
get { return _name;}
set { _name = value; }
}
public string Image {
get { return _image; }
set { _image = value; }
}
//*********************************************************************
//
// AlwaysDisplay Property
//
// Enables you to display a topic even when topics are disabled
// for a section. This property is set by the skin for the topic menu.
//
//*********************************************************************
public bool AlwaysDisplay {
get { return _alwaysDisplay; }
set { _alwaysDisplay = value; }
}
//*********************************************************************
//
// Render Method
//
// Only render if topics are enabled. We need to check for the existence
// of context to avoid a Designer error in Visual Studio .NET
//
//*********************************************************************
protected override void Render(HtmlTextWriter tw) {
if (_alwaysDisplay) {
base.Render(tw);
return;
}
if (Context.Items["SectionInfo"] != null) {
SectionInfo objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
if (objSectionInfo.EnableTopics)
base.Render(tw);
}
}
//*********************************************************************
//
// RenderContents Method
//
// Renders either the name or image for the topic.
//
//*********************************************************************
protected override void RenderContents(HtmlTextWriter tw) {
string imageTag;
string imagePath;
// Calculate topic path
string topicPath = String.Format("~/Topic.aspx?topic={0}", Context.Server.UrlEncode(_name));
topicPath = Page.ResolveUrl(topicPath);
tw.AddAttribute(HtmlTextWriterAttribute.Href, topicPath);
tw.RenderBeginTag(HtmlTextWriterTag.A);
if (Image == String.Empty)
tw.Write( _name );
else {
imagePath = Page.ResolveUrl( "~/" + _image);
imageTag = String.Format("<img src=\"{0}\" ALT=\"{1}\" border=\"0\">", imagePath, _name);
tw.Write(imageTag);
}
tw.RenderEndTag();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -