HTML presentation of Control at the server side.

M

marss

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.
 

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

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top