📄 emailarticlepanel.ascx.cs
字号:
namespace Interspire.ArticleLive.Web.Templates.BrightLightFixed.Panels
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
public abstract class EmailArticlePanel : BaseUserControl
{
protected System.Web.UI.WebControls.TextBox YourName;
protected CustomRequiredFieldValidator YourNameReqVal;
protected System.Web.UI.WebControls.TextBox YourEmail;
protected CustomRequiredFieldValidator YourEmailReqVal;
protected System.Web.UI.WebControls.TextBox FriendsName;
protected CustomRequiredFieldValidator FriendsNameReqVal;
protected System.Web.UI.WebControls.TextBox FriendsEmail;
protected CustomRequiredFieldValidator FriendsEmailReqVal;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button SendButton;
protected Interspire.ArticleLive.Web.MessageControl MessageControl1;
protected Interspire.ArticleLive.Web.ValidationAlerter ValidationAlerter1;
protected Interspire.ArticleLive.Web.MessageControl Messagecontrol2;
protected System.Web.UI.HtmlControls.HtmlTable FormTable;
protected System.Web.UI.HtmlControls.HtmlTable SuccessTable;
protected Interspire.ArticleLive.Web.CustomRegularExpressionValidator YourEmailRegExpVal;
protected Interspire.ArticleLive.Web.CustomRegularExpressionValidator FriendsEmailRegExpVal;
protected Article CurrentArticle
{
get { return (Article)ViewState["CurrentArticle"]; }
set { ViewState["CurrentArticle"] = value; }
}
private ArticleEngine articleEngine;
public ArticleEngine ArticleEngine
{
get
{
if (articleEngine == null)
articleEngine = new ArticleEngine(Config.Current);
return articleEngine; }
}
protected string Message
{
get
{
if (ViewState["Message"] == null)
ViewState["Message"] = String.Empty;
return (string)ViewState["Message"]; }
set { ViewState["Message"] = value; }
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["ArticleID"] == null)
throw new ArgumentNullException("ArticleID", "The ArticleID querystring was not found.");
else
{
int articleID = Convert.ToInt32(Request.QueryString["ArticleID"]);
CurrentArticle = ArticleEngine.GetArticle(articleID, false, false, false, false, false, true);
WindowTitle = String.Format(ResourceHelper.GetString("EmailCurrentArticleToFriend"), CurrentArticle.Title);
// Example message: ResourceHelper.GetString("EmailArticleToFriendMessage")
//"Hi {FriendsName},\n\nI found an article at {WebSiteName} called '{ArticleTitle}' that I thought would be of interest to you. The link is: {ArticleLink}\n\nRegards,\n{YourName}\n{YourEmail}"
Message = ResourceHelper.GetString("EmailArticleToFriendMessage");
Message = Message.Replace("{WebSiteName}", Config.Current.WebSiteName);
Message = Message.Replace("{ArticleTitle}", CurrentArticle.Title);
Message = Message.Replace("{ArticleLink}", LinkHelper.CreateArticleLink(CurrentArticle, true));
Message = Message.Replace("<br>", "\n");
Message = Message.Replace("<br>", "\n");
DataBind();
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SendButton.Click += new System.EventHandler(this.SendButton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void SendButton_Click(object sender, System.EventArgs e)
{
if (IsValid)
{
MailMessage message = new MailMessage();
message.BodyFormat = MailFormat.Html;
message.To = FriendsEmail.Text;
message.From = YourEmail.Text;
message.Body = Message.Replace("{FriendsName}", FriendsName.Text).Replace("{YourName}", YourName.Text).Replace("{YourEmail}", YourEmail.Text).Replace("\n", "<br>");;
message.Subject = ResourceHelper.GetString("EmailArticleToFriendSubject").Replace("{0}", Config.Current.WebSiteName);
SmtpMail.SmtpServer = Config.Current.SmtpServer;
SmtpMail.Send(message);
ArticleEngine.RecordArticleEmail(CurrentArticle.ArticleID);
MessageControl.Display(ResourceHelper.GetString("EmailToFriendSuccess"));
SuccessTable.Visible = true;
FormTable.Visible = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -