思路:在button的client click中把页面的内容存到一个hidden filed中,在server端的click中读取并发送
asp:Button ID=”Button_SendMail” runat=”server” Text=”SendEmail” OnClientClick=”CellPostBack();” OnClick=”Button_SendMail_Click”
function CellPostBack()
{
var result = document.getElementById(”result”);
var hiddenInfo = document.getElementById(”hiddenInfo”);
//alert(result.innerText);
//hiddenInfo.value = result.innerHTML;
}
protected void Button_SendMail_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.hiddenInfo.Value))
this.SendMail(this.hiddenInfo.Value);
}
private void SendMail( string body)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(”aloneplayer@gmail.com“, “aLONEPLayer”);
smtpClient.Host = “XXXXX”;
//smtpClient.Port = 25;
message.From = fromAddress;
message.To.Add(”aloneplayer@gmail.com“);
message.Subject = “Hi, I’am Riven”;
message.IsBodyHtml = true;
message.Body = body;
smtpClient.Send(message);
}
还需要关闭Asp.net对页面内容的校验
<pages validateRequest=”false”/>