Some controls cannot RenderControl
- From: "Josh Carver" <josh.carver@nospam>
- Date: Mon, 9 Jul 2007 07:46:48 -0400
Hi group,
I'm trying to get the outputted html from some specific controls on a page, and I'm finding that some controls will render fine, while others will throw the error that "[control] must be placed inside a form tag with runat=server." For example, a label control will render fine, but a button will not. It seems that any control that has a server-side click event will not accept being rendered in this way. Does anyone know what I can do to get such controls to render? Here's my code:
aspx snippet:
<form id="f" runat="server">
<div>
<asp:Label ID="control" runat="server" Text="Chage to an asp:Button" />
</div>
</form>
..cs snippets:
using System;
using System.Web.UI;
using System.IO;
// ...
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter htw = new HtmlTextWriter(sw);
control.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Thanks for any help.
Joshua C
.
- Follow-Ups:
- RE: Some controls cannot RenderControl
- From: Milosz Skalecki [MCAD]
- RE: Some controls cannot RenderControl
- Prev by Date: Re: Master page postback.. !IsPostback doesnt work
- Next by Date: How do you set the forecolor of a disabled linkbutton?
- Previous by thread: ENTER key in TextBox in ASP.NET 2.0
- Next by thread: RE: Some controls cannot RenderControl
- Index(es):