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