📄 additem.cs
字号:
namespace ASPNET.StarterKit.Communities {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
//*********************************************************************
//
// AddContent Class
//
// Represents a link to a page to add new content.
// 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 add permissions before displaying the link.
//
//*********************************************************************
[Designer(typeof(ASPNET.StarterKit.Communities.CommunityDesigner))]
public class AddContent : WebControl {
private string _text = String.Empty;
private string _navigateUrl = String.Empty;
private string _imageUrl = String.Empty;
//*********************************************************************
//
// Text Property
//
// The text to display in the Hyperlink
//
//*********************************************************************
public string Text {
get {return _text;}
set {_text = value;}
}
//*********************************************************************
//
// NavigateUrl Property
//
// The path to the addcontent page (this should always be a link
// to a page in the same section).
//
//*********************************************************************
public string NavigateUrl {
get {return _navigateUrl;}
set {_navigateUrl = value;}
}
//*********************************************************************
//
// ImageUrl Property
//
// The path for the (optional) picture to display in the hyperlink.
//
//*********************************************************************
public string ImageUrl {
get {return _imageUrl;}
set {_imageUrl = value;}
}
//*********************************************************************
//
// AddAttributesToRender Method
//
// Add the HRef that links to the AddContent page
//
//*********************************************************************
protected override void AddAttributesToRender(HtmlTextWriter writer) {
writer.AddAttribute(HtmlTextWriterAttribute.Href, CommunityGlobals.CalculatePath(_navigateUrl));
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.MayAdd || Array.IndexOf(objSectionInfo.AddRoles, "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 + -