Monday, July 19, 2010

must be placed inside a form tag with runat=server

I got to explain the scenario I cameacross this issue, as this might vary for some other scenarios. I got this error when I try to override the PreRender event of the masterpage's
Content Holder (idea was to get the html of that area what evel loding in to that).


ContentPlaceHolder cph = (ContentPlaceHolder)Master.Controls[0].FindControl("master_content_holder");
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var htmlTxtWr = new HtmlTextWriter(sw);
SmtpUtil smtpUtil = new SmtpUtil();
cph.RenderControl(htmlTxtWr);

I got this error exactly on the last line of code. As error message states our all controlls must be inside a form tag with runat = server (note you can't have form tags on child pages, do not try it, it won't work). I did a small dirty work as to fix this issue.
I just overrided the VerifyRenderingInServerForm mehtod on child page. For me it worked properly, as i didn't have any verification to be done on my page. Be carefull before use.

0 comments:

My Achievements

Member of

Blog Archive

Followers