📄 itemcommentreply.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// ItemCommentReply Class
//
// Represents a link to a page to add a comment.
// This was originally implemented by overriding the HyperLink control.
// Unfortunately, the HyperLink control does not resolve paths
// correctly when used in skins, so we have to do some extra work.
// This control will also check comment permissions before displaying the link.
//
//*********************************************************************
[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
public class ItemCommentReply : WebControl {
private string _text = String.Empty;
private string _imageUrl = String.Empty;
private string _replyUrl = "Comments_AddComment.aspx?id={0}&ReturnUrl={1}";
//*********************************************************************
//
// ItemCommentReply Constructor
//
// Assign a default css class and disable view state
//
//*********************************************************************
public ItemCommentReply() : base() {
CssClass = "itemCommentReply";
EnableViewState = false;
}
//*********************************************************************
//
// Text Property
//
// The text to display in the Hyperlink
//
//*********************************************************************
public string Text {
get {return _text;}
set {_text = value;}
}
//*********************************************************************
//
// ImageUrl Property
//
// The path for the (optional) picture to display in the hyperlink.
//
//*********************************************************************
public string ImageUrl {
get {return _imageUrl;}
set {_imageUrl = value;}
}
//*********************************************************************
//
// ReplyUrl Property
//
// The path for the comment page (defaults to the standard one).
//
//*********************************************************************
public string ReplyUrl {
get {return _replyUrl;}
set {_replyUrl = value;}
}
//*********************************************************************
//
// ContentPageID Property
//
// The contentPageID being commented.
//
//*********************************************************************
public int ContentPageID {
get {
if (ViewState["ContentPageID"] == null)
return -1;
else
return (int)ViewState["ContentPageID"];
}
set {ViewState["ContentPageID"] = value;}
}
//*********************************************************************
//
// OnDataBinding Method
//
// Grab the ContentPageID from the containing control's DataItem
//
//*********************************************************************
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;
ContentPageID = objContentInfo.ContentPageID;
}
//*********************************************************************
//
// AddAttributesToRender Method
//
// Add the HRef that links to the AddContent page
//
//*********************************************************************
protected override void AddAttributesToRender(HtmlTextWriter writer) {
ContentInfo _parentContentInfo = (ContentInfo)Context.Items["ContentInfo"];
string replyLink = String.Format(_replyUrl, ContentPageID, HttpUtility.UrlEncode(String.Format("{0}.aspx", _parentContentInfo.ContentPageID)));
writer.AddAttribute(HtmlTextWriterAttribute.Href, CommunityGlobals.CalculatePath(replyLink));
base.AddAttributesToRender(writer);
}
//*********************************************************************
//
// Render Method
//
// Here's where we check add permissions
//
//*********************************************************************
override protected void Render(HtmlTextWriter writer) {
UserInfo objUserInfo = (UserInfo)Context.Items["UserInfo"];
SectionInfo objSectionInfo = (SectionInfo)Context.Items["SectionInfo"];
if (objUserInfo.MayComment||Array.IndexOf(objSectionInfo.CommentRoles, "Community-Authenticated" )!=-1)
base.Render(writer);
}
//*********************************************************************
//
// RenderContents Method
//
// Display the contents of the link
//
//*********************************************************************
override protected void RenderContents(HtmlTextWriter writer) {
if (_imageUrl == String.Empty)
writer.Write(_text);
else
writer.Write(String.Format("<img src=\"{0}\" alt=\"{1}\" border=\"0\" />", Page.ResolveUrl(_imageUrl), _text));
}
//*********************************************************************
//
// TagKey Property
//
// We want to create an A tag around the content of this control
//
//*********************************************************************
override protected HtmlTextWriterTag TagKey {
get { return HtmlTextWriterTag.A; }
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -