HTML presentation of Control at the server side.

Discussion in 'ASP .Net Web Controls' started by marss, Jun 23, 2006.

  1. marss

    marss Guest

    While page is rendered server-side control <asp:TextBox id="TextBox1"
    runat="server"></asp:TextBox> is converted to <input name="TextBox1"
    type="text" id="TextBox1" />.

    Is there any way to get HTML presentation of WebControl or UserControl
    at the server side?

    I'll try RenderControl method:
    ....
    StringBuilder sb = new StringBuilder();
    TextBox1.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
    string res = sb.ToString();
    .....
    But it always throws the exception "Control 'TextBox1' of type
    'TextBox' must be placed inside a form tag with runat=server."

    Thanks for reply, Jon

    In fact, the textbox is placed inside of the form tag with
    runat=server, but when I call RenderControl method of single control
    separately from whole page rendering, it rises the exception.
    Example:

    cs:
    private void Page_Load(object sender, System.EventArgs e)
    {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    TextBox1.RenderControl(new HtmlTextWriter(new
    System.IO.StringWriter(sb)));
    string res = sb.ToString();
    }

    aspx:
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
    </form>
    </body>

    But maybe I'm going the wrong way.
    All I need is HTML presentation of Control at the server side.
     
    marss, Jun 23, 2006
    #1
    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.

Share This Page