📄 author.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// Author Class
//
// Represents a content author
//
//*********************************************************************
[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
public class Author : WebControl {
private string _externalImage = "~/communities/common/images/external.gif";
ContentInfo objContentInfo;
//*********************************************************************
//
// Author Constructor
//
// Assign a default css class and retrieve contentInfo from context
//
//*********************************************************************
public Author() : base() {
CssClass = "Author";
// Get ContentInfo object
if (Context != null)
objContentInfo = (ContentInfo)Context.Items["ContentInfo"];
}
//*********************************************************************
//
// ExternalImage Property
//
// The relative path to an image displayed for remote users
//
//*********************************************************************
public string ExternalImage {
get {return _externalImage;}
set {_externalImage = value; }
}
//*********************************************************************
//
// TagKey Property
//
// If local user display a link, otherwise display a span
//
//*********************************************************************
protected override HtmlTextWriterTag TagKey {
get {
if (objContentInfo.RemoteAuthor == String.Empty)
return HtmlTextWriterTag.A;
else
return HtmlTextWriterTag.Span;
}
}
//*********************************************************************
//
// AddAttributesToRender Method
//
// Add the HRef that links to the profile page
//
//*********************************************************************
protected override void AddAttributesToRender(HtmlTextWriter writer) {
if (objContentInfo.RemoteAuthor == String.Empty) {
string encodedAuthor = String.Format("Users_ShowProfile.aspx?user={0}", Context.Server.UrlEncode(objContentInfo.Author));
writer.AddAttribute(HtmlTextWriterAttribute.Href, encodedAuthor);
base.AddAttributesToRender(writer);
}
}
//*********************************************************************
//
// RenderContents Method
//
// Display author (we HTML encode here)
//
//*********************************************************************
override protected void RenderContents(HtmlTextWriter writer) {
if (objContentInfo.RemoteAuthor == String.Empty)
writer.Write(Context.Server.HtmlEncode(objContentInfo.Author));
else {
writer.Write(String.Format("<img src=\"{0}\" />", Page.ResolveUrl(_externalImage)));
writer.Write(Context.Server.HtmlEncode(objContentInfo.RemoteAuthor));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -