⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editarticle.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities.Articles {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using ASPNET.StarterKit.Communities;


    //*********************************************************************
    //
    // EditArticle Class
    //
    // Represents the Edit Article page. Enables users to edit articles.
    //
    //*********************************************************************

    public class EditArticle : ContentEditPage {
    
        string _skinFileName = "Articles_AddArticle.ascx";
        string _sectionContent = "ASPNET.StarterKit.Communities.Articles.ArticleSection";
 
 
        TextBox txtTitle;
        TopicPicker dropTopics;
        TextBox txtBriefDescription;
        HtmlTextBox txtBodyText;
 
        Title lblPreviewTitle;
        DisplayTopic topicPreview;
        BriefDescription lblPreviewBriefDescription;
        ArticleBodyText 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; }
        }




        //*********************************************************************
        //
        // SkinLoadArticle Method
        //
        // This method is called when the skin is being initialized.
        //
        //*********************************************************************

        void SkinLoadArticle(Object s, SkinLoadEventArgs e) {
  
            // Find Title
            txtTitle = (TextBox)GetControl(e.Skin, "txtTitle");

            // Find Topic Picker
            dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
            
            // Find Intro Text 
            txtBriefDescription = (TextBox)GetControl(e.Skin, "txtBriefDescription");

            // Find Body Text
            txtBodyText = (HtmlTextBox)GetControl(e.Skin, "txtBodyText");
           
            // Find Preview Title
            lblPreviewTitle = (Title)GetControl(e.Skin, "lblPreviewTitle");
            
            // Find the topic preview
            topicPreview = (DisplayTopic)GetControl(e.Skin, "topicPreview");
            
            // Find Preview Intro Text
            lblPreviewBriefDescription = (BriefDescription)GetControl(e.Skin, "lblPreviewBriefDescription");
            
            // Find Preview Body Text
            lblPreviewBodyText = (ArticleBodyText)GetControl(e.Skin, "lblPreviewBodyText");
        }
        




        //*********************************************************************
        //
        // OnLoad Method
        //
        // Assign previous content values to edit form.
        //
        //*********************************************************************

        protected override void OnLoad(EventArgs e) {
            if (!Page.IsPostBack) {
                ContentPageID = Int32.Parse(Context.Request.QueryString["id"]);
                
			    // Get the article info
			    ArticleInfo _articleInfo = (ArticleInfo)ArticleUtility.GetArticleInfo(objUserInfo.Username, ContentPageID);
                
                // Assign Values
                EnsureChildControls();
                txtTitle.Text = _articleInfo.Title;
                dropTopics.SelectedTopicID = _articleInfo.TopicID;
                txtBriefDescription.Text = _articleInfo.BriefDescription;
                txtBodyText.Text = _articleInfo.BodyText;
            }
        }
        



        //*********************************************************************
        //
        // PreviewArticle Method
        //
        // This method is raised by clicking the Preview button in the Edit 
        // form.
        //
        //*********************************************************************

        void PreviewArticle(Object s, EventArgs e) {
            lblPreviewTitle.Text = txtTitle.Text;
            if (objSectionInfo.EnableTopics)
                topicPreview.Name = dropTopics.SelectedItem.Text;
            lblPreviewBriefDescription.Text = txtBriefDescription.Text;
            lblPreviewBodyText.Text = txtBodyText.Text; 
        }



        //*********************************************************************
        //
        // SubmitArticle Method
        //
        // This method is raised by clicking the Edit button in the Edit 
        // form.
        //
        //*********************************************************************

        void SubmitArticle(Object s, EventArgs e) {
		  if (Page.IsValid) {
			     // Get Topic
			     int _topicID = -1;
			     if (objSectionInfo.EnableTopics)
			         _topicID = Int32.Parse(dropTopics.SelectedItem.Value);    

           
                // Edit Content Page
                ArticleUtility.EditArticle
                (
                    objUserInfo.Username,
                    objSectionInfo.ID,
                    ContentPageID,
                    _topicID,
                    txtTitle.Text,
                    txtBriefDescription.Text,
                    txtBodyText.Text
                );
    
				// Redirect back to Article Page
				Context.Response.Redirect(CommunityGlobals.CalculatePath(String.Format("{0}.aspx", ContentPageID)));    
            }
        }


        //*********************************************************************
        //
        // EditArticle Constructor
        //
        // Calls the base SkinnedCommunityControl constructor
        // and assigns the default page skin. Also checks whether
        // current user has permissions to edit.
        //
        //*********************************************************************

        public EditArticle() : base() {
            // Assign a default skin file name
            SkinFileName = _skinFileName;
            
            // Specify Section Content
            SectionContent = _sectionContent;
            
            // Wire-up event handlers
            this.SkinLoad += new SkinLoadEventHandler(SkinLoadArticle);
            this.Preview += new PreviewEventHandler(PreviewArticle);
            this.Submit += new SubmitEventHandler(SubmitArticle);
        }





    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -