views:

19

answers:

2

Hi,

I have a class which generate a dynamic page.

Panel myPanel = new Panel();

TextBox myTextBox = new TextBox();

myPanel.Controls.Add(myTextBox);

Page thePage = new Page();

thePage.Form.Controls.Add(myPanel);

return thePage;

my class basically do this. I call my class and I get thePage object from code-behind. Now, How can I render this page object and show it to user like a .aspx file?

Thank you.

A: 

You MIGHT be able to use the Render method on the Page. However, I have never seen a Page used this way so I'm doubtful that it will work. Look in the help for the Render method of the Page class.

Bomlin
//StringWriter stringWrite = new StringWriter(); //HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); //thePage.DesignerInitialize(); //thePage.RenderControl(htmlWrite); //string strHTML = stringWrite.ToString();I use these codes for rendering but I have lots of problem. Is there any solution you offer?
Can
A: 

Anything's possible, but it's certainly more work that in's worth. To make the controls work properly you would have to replicate most of the page cycle that a regular request goes through, complete with events, viewstate, rendering and everything.

Why are you trying to create a Page object outside of it's element anyway? You need a request from the browser in order to return a response anyway, so why not just use a regular page?

Guffa
because all controls generated dynamically, I need to generate the page dynamically, so I can set the page's properties, events dynamically. Now, my solution is up to dynamically generated panel. I embed the panel to regular page...
Can
It's perfectly doable to put dynamically generated controls in a page. It's slightly tricky to recreate them correctly on postback and to hook up events, but it's way way simpler than simulating a complete page cycle...
Guffa