Charlie Morrison
Charlie Morrison

Reputation: 41

copy asp control

I am trying to copy data that is displayed in a asp listview.(I want to email it)

I can grab the information using javascript to grab the html but it is unstyled.

I don't want to have to go inside each control to save the data before each time it is outputted. Is their a better solution?

Upvotes: 1

Views: 82

Answers (2)

Kevin Anderson
Kevin Anderson

Reputation: 589

I know this has been answered, but I thought I would add this too in case it helps. I use the following to return the HTML of a given control. As mentioned, you would just need to include any CSS in the HTML of the Email.

using System.Text;
using System.IO;
using System.Web.UI;

public string RenderControl(Control ctrl)
{
    StringBuilder sb = new StringBuilder();
    StringWriter tw = new StringWriter(sb);
    HtmlTextWriter hw = new HtmlTextWriter(tw);

    ctrl.RenderControl(hw);
    return sb.ToString();
}

Stolen from several blog sites like this one.

Upvotes: 0

Eric Herlitz
Eric Herlitz

Reputation: 26267

Html is html, if you keep your formatting in a css you will need to attach related css-classes and tags in the e-mails as well which should be quite simple.

Upvotes: 1

Related Questions