我需要获取Html
并GridView
发送电子邮件。
我的GridView
设计如下所述
<div id="DivEmail" class="clear">
<asp:Repeater ID="rpt1" runat="server" OnItemDataBound="rpt1_ItemDataBound">
<ItemTemplate>
<asp:HiddenField ID="TypeID" runat="server" Value='<%# Eval("TypeID") %>' />
<div id='Handle<%# Eval("TypeName")%>' class="ulheader" >
<asp:Label ID="lblType" runat="server" Text='<%# Eval("TypeName")%>' ></asp:Label>
</div>
<div id="Reuslt<%# Eval("TypeName")%>">
<asp:GridView ID="grvReport" runat="server" Width="100%" BorderColor="#e4e4e4" border="0" Style="border-collapse: collapse;" ShowHeader="true" CellPadding="5" CellSpacing="0" AutoGenerateColumns="false" EmptyDataText="No Results Found" AllowPaging="false" AllowSorting="false" CssClass="grid grid-iq" BackColor="#FFFFFF">
<Columns>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="thumb" Width="100px" Height="100px" runat="server" ImageUrl='<%# Eval("ImageUrl") %>'
ImageAlign="Middle" />
</ItemTemplate>
ItemStyle CssClass="center" Height="20px" />
<HeaderStyle CssClass="grid-th center" Width="100px" VerticalAlign="Top" />
</asp:TemplateField>
<asp:BoundField DataField="Title" HeaderText="Title">
<HeaderStyle Height="20px" Width="20%" CssClass="grid-th-left" VerticalAlign="Top" />
<ItemStyle CssClass="left"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Description" HeaderText="Description">
<HeaderStyle Height="20px" Width="28%" CssClass="grid-th-left" VerticalAlign="Top" />
<ItemStyle CssClass="left"></ItemStyle>
</asp:BoundField>
<asp:TemplateField ShowHeader="false" HeaderText="View">
<ItemTemplate>
<asp:LinkButton ID="lbtnLink" runat="server" CommandArgument='<%# Bind("ID") %>'
OnCommand="lbtnView_OnCommand" Text="View"></asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="center" Height="20px" />
<HeaderStyle CssClass="grid-th center" Width="9%" VerticalAlign="Top" />
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="grid-th" Height="10px" HorizontalAlign="Center" VerticalAlign="Top"></HeaderStyle>
</asp:GridView>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
为了获取Html
服务器控制权,我使用下面的代码
protected void btnOK_Click(object sender, EventArgs e)
{
var sb = new StringBuilder();
DivEmail.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
EmailContent += sb.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}
通过这样做,我得到了异常
RegisterForEventValidation can only be called during Render()
我在这个问题上搜索了一下,结果显示设置EnableEventValidation="false"
为@page directive
. 但我不能使用这个解决方案。
有人可以帮我解决这个问题吗?