?? editpost.cs
字號(hào):
namespace ASPNET.StarterKit.Communities.Discuss {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// EditPost Class
//
// Represents the Edit Post page. Enables users to edit messages.
//
//*********************************************************************
public class EditPost : ContentEditPage {
string _skinFileName = "Discuss_AddPost.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Discuss.DiscussSection";
Label lblUsername;
TextBox txtTitle;
TopicPicker dropTopics;
HtmlTextBox txtBodyText;
Panel pnlModerateOptions;
CheckBox chkPinned;
CheckBox chkAnnouncement;
CheckBox chkLocked;
Title lblPreviewTitle;
DisplayTopic topicPreview;
PostBodyText lblPreviewBodyText;
//*********************************************************************
//
// ContentPageID Property
//
// Stores the ID of the content being edited in View State
//
//*********************************************************************
int ContentPageID {
get {
return (int)ViewState["ContentPageID"];
}
set { ViewState["ContentPageID"] = value; }
}
//*********************************************************************
//
// SkinLoadPost
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadPost(Object s, SkinLoadEventArgs e) {
// Find Username Label
lblUsername = (Label)GetControl(e.Skin, "lblUsername");
// Find Title
txtTitle = (TextBox)GetControl(e.Skin, "txtTitle");
// Find Topic Picker
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
// Find Body Text
txtBodyText = (HtmlTextBox)GetControl(e.Skin, "txtBodyText");
// Find Moderator Panel
pnlModerateOptions = (Panel)GetControl(e.Skin, "pnlModerateOptions");
if (objUserInfo.MayEdit || objUserInfo.MayModerate)
pnlModerateOptions.Visible = true;
else
pnlModerateOptions.Visible = false;
// Find Pinned Checkbox
chkPinned = (CheckBox)GetControl(e.Skin, "chkPinned");
// Find Announcement Checkbox
chkAnnouncement = (CheckBox)GetControl(e.Skin, "chkAnnouncement");
// Find Announcement Checkbox
chkLocked = (CheckBox)GetControl(e.Skin, "chkLocked");
// Find Preview Title
lblPreviewTitle = (Title)GetControl(e.Skin, "lblPreviewTitle");
// Find the topic preview
topicPreview = (DisplayTopic)GetControl(e.Skin, "topicPreview");
// Find Preview Body Text
lblPreviewBodyText = (PostBodyText)GetControl(e.Skin, "lblPreviewBodyText");
}
//*********************************************************************
//
// OnLoad Method
//
// Assigns values to the controls from the page skin.
//
//*********************************************************************
override protected void OnLoad(EventArgs e) {
if (!Page.IsPostBack) {
// Get the ContentPageID from QueryString
ContentPageID = Int32.Parse(Page.Request.QueryString["id"]);
// Get the post info
PostInfo _postInfo = (PostInfo)DiscussUtility.GetPostInfo(objUserInfo.Username, ContentPageID);
EnsureChildControls();
// Assign value to topics
dropTopics.SelectedTopicID = _postInfo.TopicID;
// Assign other form values
lblUsername.Text = _postInfo.Author;
txtTitle.Text = _postInfo.Title;
txtBodyText.Text = _postInfo.BodyText;
chkPinned.Checked = _postInfo.IsPinned;
chkAnnouncement.Checked = _postInfo.IsAnnouncement;
chkLocked.Checked = _postInfo.IsLocked;
}
}
//*********************************************************************
//
// PreviewPost Method
//
// When previewing, we want to transfer everything from
// the text boxes to the labels.
//
//*********************************************************************
void PreviewPost(Object s, EventArgs e) {
lblPreviewTitle.Text = txtTitle.Text;
if (objSectionInfo.EnableTopics)
topicPreview.Name = dropTopics.SelectedItem.Text;
lblPreviewBodyText.Text = txtBodyText.Text;
}
//*********************************************************************
//
// SubmitPost Method
//
// This method is raised by clicking the Add button in the Add
// Post form. It adds the post to the database.
//
//*********************************************************************
void SubmitPost(Object s, EventArgs e) {
if (Page.IsValid) {
// Get Topic
int _topicID = -1;
if (objSectionInfo.EnableTopics)
_topicID = dropTopics.SelectedTopicID;
// Add to Content Pages
DiscussUtility.EditPost
(
ContentPageID,
objUserInfo.Username,
objSectionInfo.ID,
_topicID,
txtTitle.Text,
chkPinned.Checked,
chkAnnouncement.Checked,
chkLocked.Checked,
txtBodyText.Text
);
// Redirect back to Post Page
Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ContentPageID)));
}
}
//*********************************************************************
//
// EditPost Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public EditPost() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Specify Section Content
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadPost);
this.Preview += new PreviewEventHandler(PreviewPost);
this.Submit += new SubmitEventHandler(SubmitPost);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -