473,414 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

render HTML output to an email?

Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an email.

Is there an easy way to do this? Any examples?

Thanks for the help!

- T
Nov 18 '05 #1
6 2160
write it all to a string and write it to the e-mail object

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Tarren" <noemailplease@thankyou> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an
email.

Is there an easy way to do this? Any examples?

Thanks for the help!

- T

Nov 18 '05 #2
use a webclient and open the webpage and read it into a stream. get the data
and use it as a body.
from an old piece of code.

WebClient wbTellAFriend = new WebClient();
NameValueCollection myQS = new NameValueCollection();
myQS.Add("ProductID", Convert.ToString(ProductID));
myQS.Add("ProductColorID", Convert.ToString(ProductColorID));
wbTellAFriend.QueryString = myQS;

bool localBuild =
bool.Parse(ConfigurationSettings.AppSettings["localBuild"]);
string appPath = (localBuild == true ?
ConfigurationSettings.AppSettings["localPath"] :
ConfigurationSettings.AppSettings["onlinePath"]);
Stream sData = wbTellAFriend.OpenRead(appPath +
"Customers/Home/WCTellAFriend.aspx");
StreamReader sDataReader = new StreamReader(sData);
string mailBody = sDataReader.ReadToEnd();
mailBody = mailBody.Replace("MemberName", txtYourName.Text.Trim() + "(" +
txtYourEmail.Text.Trim() + ")");

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Tarren" <noemailplease@thankyou> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an email.
Is there an easy way to do this? Any examples?

Thanks for the help!

- T

Nov 18 '05 #3
Hi,

here is an example.

Assume you have ASPX as follows:
***************************
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
<asp:Button ID="btnSend" Runat="server" Text="Send as email" />
<asp:Label ID="lblInfo" Runat="server" />
</form>
***************************
And code as follows on page:
***************************
Private Sub BindGrid()
'Create an example data source
Dim dt As New DataTable
dt.Columns.Add("ID", GetType(System.Int32))
dt.Columns("ID").AutoIncrement = True
dt.Columns.Add("Text", GetType(System.String))

Dim dr As DataRow = dt.NewRow()
dr(1) = "First"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(1) = "Second"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(1) = "Third"
dt.Rows.Add(dr)

'Bind the dataGrid
DataGrid1.DataSource = dt
DataGrid1.DataBind()

End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here

If Not Page.IsPostBack Then
BindGrid()
End If

'If email was sent
If Request.QueryString("emailsent") = "true" Then
lblInfo.Text = "Email was sent"
End If
End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSend.Click
'Set flag to indicate we want to send an email
Context.Items("sendasemail") = True
End Sub
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)

'Rendering logic varies based on if rendering or sending the email
If Context.Items("sendasemail") Is Nothing Then
MyBase.Render(writer)
Else

'Get the HTML output
Dim htmlStringWriter As New IO.StringWriter
Dim customHtmlWriter As New HtmlTextWriter(htmlStringWriter)

'We are only interested in the DataGrid's output
DataGrid1.RenderControl(customHtmlWriter)

'If you want to get the complete page output
'Use MyBase.Render(customHtmlWriter)

'Send the email
Dim mailmsg As New Mail.MailMessage
mailmsg.To = "re******@domain.com"
mailmsg.From = "se****@domain.com"
mailmsg.Subject = "Page you requested"

mailmsg.Body = htmlStringWriter.ToString()
mailmsg.BodyFormat = Mail.MailFormat.Html
System.Web.Mail.SmtpMail.SmtpServer = "yoursmtpserver"
System.Web.Mail.SmtpMail.Send(mailmsg)
Response.Redirect(Request.Url.AbsoluteUri & "?emailsent=true")
End If
End Sub
***************************************

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Tarren" <noemailplease@thankyou> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an email.
Is there an easy way to do this? Any examples?

Thanks for the help!

- T

Nov 18 '05 #4
thanks all!
"Tarren" <noemailplease@thankyou> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an
email.

Is there an easy way to do this? Any examples?

Thanks for the help!

- T

Nov 18 '05 #5

"Tarren" <noemailplease@thankyou> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an email.
Is there an easy way to do this? Any examples?

Thanks for the help!

- T

If you need some structure (and it is just data) your can try something like
this.
(ds is your dataset)
dim stw as new stringwriter
ds.writexml(stw, XmlWriteMode.IgnoreSchema )
stw.flush
youremailcode(stw.tostring())
Nov 18 '05 #6

"Tarren" <noemailplease@thankyou> wrote in message
news:ua**************@TK2MSFTNGP10.phx.gbl...
Hi:

I have an aspx page that takes a dataset, makes the datagrid, and displays
it.

The new thing I have to do is take this same output and send it as an email.
Is there an easy way to do this? Any examples?

Thanks for the help!

- T

Sorry I misread your post. This might help you.
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)
Dim html As String = _stringBuilder.ToString()
The 'html' string variable contains the html text write it out to email
here.
This writes it to the browser.
writer.Write(html)

End Sub
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: George Ter-Saakov | last post by:
I am trying to wrap PlaceHolder so it will output prefix/suffix (like <div>, </div>) before render the actual control. So i created public class clsSection : PlaceHolder protected override...
1
by: Tomas | last post by:
Is there any sequence diagram on the web that clearly shows in which order all Page methods (load, render and so on) are being called compared to the order the page's contained control methods are...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
2
by: John Olsen | last post by:
Hi. I`m building a small CMS, and want to add the possibility to include server side code inside static html-strings that is stored in a database. For e.g. in the string...
3
by: John Hughes | last post by:
I'm trying to add a user control to a form via the pages render method and I get the following error : "Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server" ...
13
by: Bob Jones | last post by:
Here is my situation: I have an aspx file stored in a resource file. All of the C# code is written inline via <script runat="server"tags. Let's call this page B. I also have page A that contains...
2
by: Nicole.Winfrey | last post by:
Hi, At the moment, I'm displaying the XML HTTP response text using javascript alert (see below). I'm trying to render XML HTTP response in a new window and the output of the window needs to be ...
2
by: Just Me | last post by:
Does anyone know if one can get to a representation of the rendered page ( after ) render. ?
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.