I have an .aspx page that I am using to handle the layout of an order receipt. I don't ever want the user to actually go to the page, I just want to populate the fields on the page and then render the HTML into a MailMessage that gets sent of to a customer. Currently I have been able to accomplish this by using Server.Execute("~/myreceipt.aspx?orderId=12345", writer) to render the HTML to a writer which I then place into the message body.
The problem with this is approach is that it limits me to either passing in the orderId to the receipt page and making a database call to pull the order info and populate the fields, or to passing each individual field via the query string and the populating the data that way (e.g ~/myreceipt.aspx?orderId=12345&customerName=John%20Smith", etc) which is rather cumbersome. What I'd LIKE to do is to pass an entire object to the aspx page in my code-behind via some property I create and then populate it that way. This way I can easily reuse the same information to pass along to multiple views, such as an order notificiation for the sales team. Since I know that ASP.NET treats all its pages as a class, I was thinking I might be able to accomplish something like:
Dim receipt As New ReceiptPage
receipt.OrderInfo = myOrderInfo
msg.Body = receipt.Render()
Does anyone know if this or a similar approach is possible?
Any help is greatly appreciated,
Mike