custom webcontrol : render and then get "html" result in server side

R

rabii

Hello,
Is there any way to render/execute my custom webcontrol in server side
then get the result (html) into string ?
 
M

Matteo Migliore

Hello.
Hello,
Is there any way to render/execute my custom webcontrol in server side
then get the result (html) into string ?

Yes, you can use this sample:
--------------------------
Button Button1 = new Button();
Button1.Text = "Click";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
Button1.RenderControl(tw);
string ret = t.ToString();
sw.Close();
tw.Close();
--------------------------

Replace Button class with yours and
the game is up!

Matteo Migliore.
 
R

rabii

Thanks men, that's what I'm looking for :).

may be :
string ret = sw.ToString(); not t.ToString() ;)
 
R

rabii

Now I have the problem with UserControl. It dosn't generate html code
(no error was shown but the result is empty).
 
M

Matteo Migliore

Excuse me for my little delay :-D.
Now I have the problem with UserControl. It dosn't generate html code
(no error was shown but the result is empty).

You can obtain HTML code from a UserControl
using the function LoadControl to instantiate the object.

Than is the same thing.

Bye,
Matteo Migliore.
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top