Home All Groups Group Topic Archive Search About

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

Author
4 May 2005 8:44 AM
rabii
Hello,
Is there any way to render/execute my custom webcontrol in server side
then get the result (html) into string ?

Author
4 May 2005 12:58 PM
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.
Author
4 May 2005 4:35 PM
rabii
Thanks men, that's what I'm looking for :).

may be :
string ret = sw.ToString(); not  t.ToString() ;)
Author
11 May 2005 1:34 PM
rabii
Now I have the problem with UserControl. It dosn't generate html code
(no error was shown but the result is empty).
Author
29 Jun 2005 4:29 PM
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.