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.

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

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

    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. Advertisements

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.