Create a page instance

  • Thread starter Rex the Strange
  • Start date
R

Rex the Strange

Hi everyone,

I'm trying to create an instance of a user page (.aspx page) from
within another .aspx page (the theory being that I can redirect the
generated content of the instantiated page into an email without
having to actually go to the page). But I'm finding that I can't
render the page instance or, when I do, the output is blank - clearly
the page isn't being processed.

I've tried the following:

public sub doit ( ... ) handles btn_doit.click
dim email_page as new email_page_type (this works ok)
email_page.custom_property = "property value" [this works ok, too
- I can see the properties and can set them]
dim text_writer as new system.io.stringwriter
dim html_writer as new htmltextwriter
email_page.rendercontrol (html_writer) [so far so good]
dim output as string = text_writer.tostring [AACK! - output is
empty!]
end sub

I've also tried:

public sub doit [blah blah blah]
dim email_page as new email_page_type
server.execute (email_page, text_writer, true/false [seems to make
no difference])

[still no luck]
end sub

Clearly there is some command that needs to be executed, presumably to
have the buildmanager actually build the page, but I can't see what it
is.

Anyone? Anyone? Please?

Tia,

Rex.
 
N

Nathan Sokalski

If you are trying to get the html generated by a page as a string, try
something like the following (which gets the html generated by my site's
home page):

Dim source As String = New System.Text.UTF8Encoding().GetString(New
System.Net.WebClient().DownloadData("http://www.nathansokalski.com/index.aspx"))

I'm not entirely sure how to use the RenderControl method technique like you
were trying to do, but I'm not sure if it would be the appropriate way here
since the HtmlTextWriter is normally used for outputting text to a page, but
it sounds like you want to output it to an email. If you do want to use the
RenderControl technique, I would do some research on how to create an
HtmlTextWriter from the ground up (normally when it is used you are using
one that is passed in as a parameter, such as in the Render method).
Hopefully this helps. Good Luck!
 
H

Hans Kesting

Rex the Strange explained on 2-12-2008 :
Hi everyone,

I'm trying to create an instance of a user page (.aspx page) from
within another .aspx page (the theory being that I can redirect the
generated content of the instantiated page into an email without
having to actually go to the page). But I'm finding that I can't
render the page instance or, when I do, the output is blank - clearly
the page isn't being processed.

I've tried the following:

public sub doit ( ... ) handles btn_doit.click
dim email_page as new email_page_type (this works ok)
email_page.custom_property = "property value" [this works ok, too
- I can see the properties and can set them]
dim text_writer as new system.io.stringwriter
dim html_writer as new htmltextwriter
email_page.rendercontrol (html_writer) [so far so good]
dim output as string = text_writer.tostring [AACK! - output is
empty!]
end sub

I've also tried:

public sub doit [blah blah blah]
dim email_page as new email_page_type
server.execute (email_page, text_writer, true/false [seems to make
no difference])

[still no luck]
end sub

Clearly there is some command that needs to be executed, presumably to
have the buildmanager actually build the page, but I can't see what it
is.

Anyone? Anyone? Please?

Tia,

Rex.

One problem is that your "email_page_type" refers to the codebehind
class of your page. The actual page containing the html *inherits* from
this class.

Try the LoadControl() method. This does work for .ascx files, maybe it
also works for .aspx files. Give this the relative path to the aspx
file and it returns a Control, where you could call Render on.

It also has to be possible with Server.Execute, but you need to provide
the path to the aspx (that is, it's filename, relative to the current
page), not a Type.

Hans Kesting
 
R

Rex the Strange

Thanks for the followup, guys. It turns out that loadcontrol balks at
loading an aspx file (it insists that the file needs to be derived
from the usercontrol type). However, for what I'm doing, there's no
reason that the object has to be a page - a would work just fine.
Thanks for pointing me in the right direction :)

rts.
 
R

Rex the Strange

Oh, and I should have mentioned that the reason I want to get a handle
on the codebehind class is so that I can set properties from code.
Making my page a usercontrol and instantiating it with loadcontrol
allows me to do that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top