Skip to content Skip to sidebar Skip to footer

How Can I Copy Html Asp.net Vb Form/table To Send As Email

I have a few large, specifically formatted to the customer's request, tables with input. It looks similar to the following...

Solution 1:

If you override the Page's VerifyRenderingInServerForm Method to not perform the validation that is causing the issue you can get around this problem:

'This is in the Page's Code Behind.PublicOverridesSub VerifyRenderingInServerForm (control As Control)
    'Do Nothing instead of raise exception.EndSub

Solution 2:

I got this version working but did not get any user-input returned. This puts the html into an email; uses HtmlAgilityPack.

using HtmlAgilityPack;
etc.

protectedvoidbtnTableToEmail_Click(object sender, EventArgs e)
{
    try
    {
        StringWriter sw = new StringWriter();
        using(HtmlTextWriter writer = new HtmlTextWriter(sw))
        {
            writer.AddAttribute("runat", "server");
            writer.RenderBeginTag("form");

            writer.Write(GetTableHTML());

            writer.RenderEndTag();
        }

        SendEmail(sw);
    }
    catch(Exception)
    {
        throw;
    }
}

privatestringGetTableHTML()
{
    // uses HtmlAgilityPack.var html = new HtmlDocument();
    html.Load(Server.MapPath("~/yourpage.aspx")); // load a filevar root = html.DocumentNode;

    var table = root.Descendants().Where(n => n.GetAttributeValue("id", "").Equals("Table1")).Single();
    return table.InnerHtml;
}

privatevoidSendEmail(StringWriter sw)
{
    // your email routine.// ...
    msg.Body = sw.ToString();
}

Post a Comment for "How Can I Copy Html Asp.net Vb Form/table To Send As Email"