0

我需要在邮件中发送使用转发器获得的表格,是否有关于如何在邮件正文中嵌入转发器的示例?我正在使用 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>
4

3 回答 3

1

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");
于 2013-01-21T14:15:45.803 回答
0

你需要这个代码:

Public Overrides Sub VerifyRenderingInServerForm(control As Control)

End Sub
于 2013-07-09T13:20:59.187 回答
0

电子邮件不是 asp.net 页面。那里仅限于平面 HTML 控件。我将链接按钮更改为锚标记并将其链接回您的 Web 应用程序并根据查询字符串加载详细信息。

于 2013-01-21T14:20:04.273 回答