📄 addlink.cs
字号:
namespace ASPNET.StarterKit.Communities.Links {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNET.StarterKit.Communities;
//*********************************************************************
//
// AddLink Class
//
// Represents the Add Link page. Enables users to list new links.
//
//*********************************************************************
public class AddLink : ContentAddPage {
string _skinFileName = "Links_AddLink.ascx";
string _sectionContent = "ASPNET.StarterKit.Communities.Links.LinksSection";
TextBox txtUrl;
TextBox txtTitle;
TextBox txtDescription;
TopicPicker dropTopics;
LinkTitle previewLinkTitle;
BriefDescription previewDescription;
DisplayTopic previewTopic;
//*********************************************************************
//
// SkinLoadLink
//
// The skin load event happens after a page skin has been loaded.
// Here, we grab the necessary controls from the page skin.
//
//*********************************************************************
void SkinLoadLink(Object s, SkinLoadEventArgs e) {
txtTitle = (TextBox)GetControl(e.Skin,"txtTitle");
txtUrl = (TextBox)GetControl(e.Skin,"txtUrl");
txtDescription = (TextBox)GetControl(e.Skin,"txtDescription");
dropTopics = (TopicPicker)GetControl(e.Skin, "dropTopics");
previewLinkTitle = (LinkTitle)GetControl(e.Skin, "previewLinkTitle");
previewDescription = (BriefDescription)GetControl(e.Skin, "previewDescription");
previewTopic = (DisplayTopic)GetControl(e.Skin, "previewTopic" );
}
//*********************************************************************
//
// PreviewLink Method
//
// When previewing a link, we want to transfer everything from
// the text boxes to the labels.
//
//*********************************************************************
void PreviewLink(Object s, EventArgs e) {
previewLinkTitle.Text = txtTitle.Text;
previewLinkTitle.Url = txtUrl.Text;
previewDescription.Text = txtDescription.Text;
if (objSectionInfo.EnableTopics)
previewTopic.Name = dropTopics.SelectedItem.Text;
}
//*********************************************************************
//
// SubmitLink Method
//
// This method is raised by clicking the Add button in the Add
// Article form. It adds the article to the database.
//
//*********************************************************************
void SubmitLink(Object s, EventArgs e) {
if (Page.IsValid) {
// Get Topic
int topicID = -1;
if (objSectionInfo.EnableTopics)
topicID = Int32.Parse(dropTopics.SelectedItem.Value);
// Check moderation status
int moderationStatus = 1;
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
moderationStatus = 0;
// Insert
int contentPageID = LinksUtility.AddLink
(
objSectionInfo.ID,
objUserInfo.Username,
txtTitle.Text,
txtUrl.Text,
txtDescription.Text,
moderationStatus,
topicID
);
// Show warning message if moderation enabled
if (objSectionInfo.EnableModeration && !objUserInfo.MayModerate)
Context.Response.Redirect(CommunityGlobals.CalculatePath("Messages_Message.aspx?message=moderation"));
// Otherwise, redirect to default page and send notifications
Context.Server.ScriptTimeout = 10 * 60;
Context.Response.Redirect(CommunityGlobals.CalculatePath("Default.aspx"), false);
Context.Response.Flush();
Context.Response.Close();
NotifyUtility.SendNotifications(objSectionInfo.ID, contentPageID, txtTitle.Text, objUserInfo.Username);
Context.Response.End();
}
}
//*********************************************************************
//
// AddLink Constructor
//
// Calls the base SkinnedCommunityControl constructor
// and assigns the default page skin.
//
//*********************************************************************
public AddLink() : base() {
// Assign a default skin file name
SkinFileName = _skinFileName;
// Not specified
SectionContent = _sectionContent;
// Wire-up event handlers
this.SkinLoad += new SkinLoadEventHandler(SkinLoadLink);
this.Preview += new PreviewEventHandler(PreviewLink);
this.Submit += new SubmitEventHandler(SubmitLink);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -