📄 itemauthor.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// ItemAuthor Class
//
// Represents an author displayed in a template
//
//*********************************************************************
[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
public class ItemAuthor : WebControl {
private string _externalImage = "~/communities/common/images/external.gif";
//*********************************************************************
//
// ItemAuthor Constructor
//
// Set the default css class
//
//*********************************************************************
public ItemAuthor() : base() {
CssClass = "ItemAuthorLink";
EnableViewState = false;
}
//*********************************************************************
//
// ExternalImage Property
//
// The relative path to an image displayed for remote users
//
//*********************************************************************
public string ExternalImage {
get {return _externalImage;}
set {_externalImage = value; }
}
//*********************************************************************
//
// OnDataBinding Method
//
// Grab the author 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["Author"] = objContentInfo.Author;
ViewState["RemoteAuthor"] = objContentInfo.RemoteAuthor;
}
//*********************************************************************
//
// TagKey Property
//
// If local user display a link, otherwise display a span
//
//*********************************************************************
protected override HtmlTextWriterTag TagKey {
get {
if ((string)ViewState["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 ((string)ViewState["RemoteAuthor"] == String.Empty) {
string encodedAuthor = String.Format("Users_ShowProfile.aspx?user={0}", Context.Server.UrlEncode((string)ViewState["Author"]));
writer.AddAttribute(HtmlTextWriterAttribute.Href, encodedAuthor);
base.AddAttributesToRender(writer);
}
}
//*********************************************************************
//
// RenderContents method
//
// Display the link label with author name
// Notice that we HtmlEncode (Thanks Andrew D!)
//
//*********************************************************************
override protected void RenderContents(HtmlTextWriter writer) {
if ((string)ViewState["RemoteAuthor"] == String.Empty)
writer.Write(Context.Server.HtmlEncode((string)ViewState["Author"]));
else {
writer.Write(String.Format("<img src=\"{0}\" />", Page.ResolveUrl(_externalImage)));
writer.Write(Context.Server.HtmlEncode((string)ViewState["RemoteAuthor"]));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -