I'm getting the above error message. However, the page in question does indeed have a tag with runat="server" attribute on it (at design time) and the control is inside it. If I run the project, and view source, that attribute appears to be gone (not sure if that part is normal or what's causing it if it's not).
The error pops when I try to run RenderControl method. The page loads fine to begin with. Any ideas?
<form id="form1" runat="server">
<div id="hiddenMVR" runat="server" style="display:block;">
// lots of other controls in here removed for brevity
</div>
</form>
Code behind:
StringBuilder stringBuilder = new StringBuilder();
StringWriter stringWriter = new StringWriter(stringBuilder);
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
//error occurs on RenderControl
this.hiddenMVR.RenderControl(htmlTextWriter);
Apparently the below code fixes the issue, although honestly I'm not sure why, since the original error message isn't accurate:
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET server
control at run time. Used to avoid issue using RenderControl above */
}
Apparently, this overrides some built-in method that I'm not aware of, which is doing something that causes the error. Overriding it with no code prevents whatever is happening by default and thus eliminates the error.
This "fix" was mentioned in some other posts, but I didn't think it applied because the error message doesn't line up with the code.
I haven't noticed any detrimental issues from doing this.