我需要在邮件中发送使用中继器获得的表,是否有关于如何在邮件正文中嵌入中继器的示例?我用MailMessage发送邮件。我试着实现这个例子:
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
MyRepeater.RenderControl(htmlWrite);
string emailContent = stringWrite.ToString();
但是有一个错误:
Control ''m_repeater_btn" of type 'LinkButton' must be placed inside a form tag with runat=server.
即使我把标签形式,我仍然得到一个错误,我应该怎么放?
这是我的asp.net页面
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ViewMySisters.aspx.cs" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Repeater ID="MyRepeater" runat="server">
<HeaderTemplate>
<table style="border-collapse:collapse; border:1px solid grey;" width="500">
<tr>
<td style="border: 1px solid grey;">firstname</td>
<td style="border: 1px solid grey;">lastname</td>
<td style="border: 1px solid grey;">age</td>
<td style="border: 1px solid grey;">work experienes</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="border: 1px solid grey;"><%# DataBinder.Eval(Container.DataItem, "NAME")%></td>
<td style="border: 1px solid grey;"><%# DataBinder.Eval(Container.DataItem, "FAMILY NAME")%></td>
<td style="border: 1px solid grey;"><%# DataBinder.Eval(Container.DataItem, "AGE")%></td>
<td style="border: 1px solid grey;"><asp:LinkButton ID="btn" runat="server" Text=">>>>" OnCommand="btnDetails_Command" CommandArgument='<%# Eval("ID") %>' /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button ID="sendMail" runat="server" Text="send" OnClick="sendmail_Clicked" />
</asp:Content>
1)尝试执行您的页面(不是单个重复器):
private string LoadMailTemplate()
{
var sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
this.Server.Execute(this, sw, false);
}
return sb.ToString();
}
其中this
是您的页面类。
2)你也可以把你的中继器放在控制档上。下面是执行控件主体的代码:
public static string LoadMailTemplate(string templatePath)
{
var page = new Page();
Control myControl = page.LoadControl(templatePath);
var sb = new StringBuilder();
page.Controls.Add(myControl);
using (var sw = new StringWriter(sb))
{
page.Server.Execute(page, sw, false);
}
return sb.ToString();
}
调用:
string emailBody = LoadMailTemplate("~/modules/eurolight/MailTemplates/OrderMailTemplate.ascx");
电子邮件不是asp.net页面。对您来说,这些控件仅限于平面HTML控件。我更改更改链接按钮为锚标记,并将其链接回您的web应用程序,并加载基于查询字符串的详细信息。
您需要以下代码:
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
End Sub