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

Discussion in 'ASP .Net Web Controls' started by rabii, May 4, 2005.

  1. rabii

    rabii Guest

    Hello,
    Is there any way to render/execute my custom webcontrol in server side
    then get the result (html) into string ?
     
    rabii, May 4, 2005
    #1
    1. Advertising

  2. 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.
     
    Matteo Migliore, May 4, 2005
    #2
    1. Advertising

  3. rabii

    rabii Guest

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

    may be :
    string ret = sw.ToString(); not t.ToString() ;)
     
    rabii, May 4, 2005
    #3
  4. rabii

    rabii Guest

    Now I have the problem with UserControl. It dosn't generate html code
    (no error was shown but the result is empty).
     
    rabii, May 11, 2005
    #4
  5. 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.
     
    Matteo Migliore, Jun 29, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mortar
    Replies:
    4
    Views:
    2,270
    Mortar
    Jan 25, 2005
  2. Replies:
    1
    Views:
    149
  3. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    197
    Fabricio
    Sep 21, 2005
  4. Replies:
    0
    Views:
    330
  5. Michael Tan
    Replies:
    32
    Views:
    1,054
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page