?? replypost.cs
字號(hào):
namespace ASPNET.StarterKit.Communities.Discuss {
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//*********************************************************************
//
// ReplyPost Class
//
// Represents the Reply Post page. Enables users to add comments
// to posts.
//
//*********************************************************************
public class ReplyPost : SkinnedCommunityControl{
string _skinFileName = "Discuss_ReplyPost.ascx";
Panel pnlForm;
Panel pnlPreview;
TextBox txtTitle;
CommentHtmlTextBox txtBody;
Button btnAdd;
Button btnPreview;
Title lblPreviewTitle;
CommentText lblPreviewBody;
Button btnContinue;
Label lblUsername;
Label lblPostAuthor;
Label lblPostDate;
Title lblPostTitle;
PostBodyText lblPostBodyText;
//*********************************************************************
//
// ReplyPost Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin. Also checks whether
// current user has permissions to add a comment.
//
//*********************************************************************
public ReplyPost() : base() {
// Check security
if (!objUserInfo.MayComment)
CommunityGlobals.ForceLogin();
// Assign a default skin file name
if (SkinFileName == null)
SkinFileName = _skinFileName;
}
//*********************************************************************
//
// SkinType Property
//
// Specifies the skins directory where this page's skin file is located.
//
//*********************************************************************
override protected string SkinType {
get { return "ContentSkins"; }
}
//*********************************************************************
//
// ContentPageID Property
//
// Represents the Content Page ID of the resource being commented on.
//
//*********************************************************************
public int ContentPageID {
get {return (int)ViewState["ContentPageID"];}
set {ViewState["ContentPageID"] = value; }
}
//*********************************************************************
//
// ReturnUrl Property
//
// Represents the URL that the user is redirected back to
// after adding a comment.
//
//*********************************************************************
public string ReturnUrl {
get {
if (ViewState["ReturnUrl"] == null)
return String.Format("{0}.aspx", ContentPageID);
else
return (string)ViewState["ReturnUrl"];
}
set {ViewState["ReturnUrl"] = value; }
}
//*********************************************************************
//
// InitializeSkin Method
//
// Retrieves all the controls from the page skin.
//
//*********************************************************************
override protected void InitializeSkin(Control skin) {
// Find the Form Panel
pnlForm = (Panel)GetControl(skin, "pnlForm");
pnlForm.Visible = true;
// Find the Preview Panel
pnlPreview = (Panel)GetControl(skin, "pnlPreview");
// Find the Title TextBox
txtTitle = (TextBox)GetControl(skin, "txtTitle");
// Find the Username Label
lblUsername = (Label)GetControl(skin, "lblUsername");
lblUsername.Text = HttpUtility.HtmlEncode(objUserInfo.Username);
// Find the Body TextBox
txtBody = (CommentHtmlTextBox)GetControl(skin, "txtBody");
// Find Add Button
btnAdd = (Button)GetControl(skin, "btnAdd");
btnAdd.Click += new EventHandler(btnAdd_Click);
// Find Preview Button
btnPreview = (Button)GetControl(skin, "btnPreview");
btnPreview.Click += new EventHandler(btnPreview_Click);
// Find Preview Title
lblPreviewTitle = (Title)GetControl(skin, "lblPreviewTitle");
// Find Preview Body
lblPreviewBody = (CommentText)GetControl(skin, "lblPreviewBody");
// Find Continue Button
btnContinue = (Button)GetControl(skin, "btnContinue");
btnContinue.CausesValidation = false;
btnContinue.Click += new EventHandler(btnContinue_Click);
lblPostAuthor = (Label)GetControl(skin, "lblPostAuthor");
lblPostDate = (Label)GetControl(skin, "lblPostDate");
lblPostTitle = (Title)GetControl(skin, "lblPostTitle");
lblPostBodyText = (PostBodyText)GetControl(skin, "lblPostBodyText");
}
//*********************************************************************
//
// OnLoad Method
//
// Assigns values to the controls from the page skin.
//
//*********************************************************************
protected override void OnLoad(EventArgs e) {
EnsureChildControls();
if (!Page.IsPostBack)
{
// Determine content page
ContentPageID = Int32.Parse(Context.Request.QueryString["id"]);
ReturnUrl = Context.Request.QueryString["ReturnUrl"];
// Hide preview panel
pnlPreview.Visible = false;
}
// Get the contents of the message being replied to
PostInfo _postInfo = (PostInfo)DiscussUtility.GetPostInfo(objUserInfo.Username, ContentPageID);
// Check that user can reply to this post
if (_postInfo.IsLocked)
throw new Exception("Cannot reply to this post!");
// Show previous post content
lblPostAuthor.Text = HttpUtility.HtmlEncode(_postInfo.Author);
lblPostDate.Text = _postInfo.DateCreated.ToLocalTime().ToString("F");
lblPostTitle.Text = _postInfo.Title;
lblPostBodyText.Text = _postInfo.BodyText;
if (!Page.IsPostBack)
{
txtTitle.Text = _postInfo.Title;
}
}
//*********************************************************************
//
// btnAdd_Click Method
//
// This method is raised by clicking the Add button in the Add
// Comment form.
//
//*********************************************************************
void btnAdd_Click(Object s, EventArgs e) {
ModerationStatus moderationStatus = ModerationStatus.Approved;
if (Page.IsValid) {
// Determine moderation status
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
moderationStatus = ModerationStatus.Pending;
// Add the comment
int _contentPageID = DiscussUtility.AddPostReply(ContentPageID, moderationStatus, objUserInfo.Username, txtTitle.Text,txtBody.Text);
// Show warning message if moderation enabled
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("Messages_Message.aspx?message=moderation&ReturnUrl={0}", HttpUtility.UrlEncode(ReturnUrl))));
// Otherwise, redirect back and send notifications
Context.Response.BufferOutput = false;
Context.Response.Redirect(CommunityGlobals.CalculatePath(ReturnUrl), false);
NotifyUtility.SendNotifications(objSectionInfo.ID, _contentPageID, txtTitle.Text, objUserInfo.Username);
Context.Response.End();
}
}
//*********************************************************************
//
// btnPreview_Click Method
//
// This method is raised by clicking the Preview button in the Add
// Comment form.
//
//*********************************************************************
void btnPreview_Click(Object s, EventArgs e) {
EnsureChildControls();
// Display preview panel
pnlPreview.Visible = true;
pnlForm.Visible = false;
// Display preview content
lblPreviewTitle.Text = txtTitle.Text;
lblPreviewBody.Text = txtBody.Text;
}
//*********************************************************************
//
// btnContinue_Click Method
//
// This method is raised by clicking the Continue button in the Add
// Comment form.
//
//*********************************************************************
void btnContinue_Click(Object s, EventArgs e) {
EnsureChildControls();
// Hide preview panel
pnlPreview.Visible = false;
pnlForm.Visible = true;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -