Server.Execute Issues Capturing resulting HTML from aspx page execution.
-
I'm currently buidling an ASP.NET application that requires custom HTML emails be sent. I was going to use "Sever.Execute" to capture the result of an aspx template execution and use it as the body of an HTML email. This works, but it only works if it is called from the "Page_Load" Sub. As soon as I call it from an event sub it fails and returns a "Corrupt ViewState" Error. Is this normal? Does "Server.Execute" only work in Page_Load? Is there another/better way to do this? Help is appreciated. Code: **** This Works **** Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SendItDude() End Sub **** This Doesn't Work *** Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click SendItDude() End Sub Public Sub SendItDude() Dim EM As CarSystem.Emailer = New CarSystem.Emailer() Dim writer As New StringWriter() Dim x As Integer = 1 Dim List(x) As Integer List(0) = 3332 List(1) = 3332 Server.Execute("../Assignpreview.aspx?car_id=7", writer) Response.Write(EM.Email_it(8, List, 3332, "This is a test", writer.ToString())) End Sub