I was creating an online test and I wanted to email the test results by topic to an email distribution list. I have a panel which has two child controls, a label with an overall % correct and a gridview with percentages by topic.
A few simple lines of code would typically handle this:
string listRecipients = ConfigurationManager.AppSettings["candidateTestEmailList"].ToString();
StringBuilder sb = new StringBuilder(2000);
pnlResults.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(sb)));
//---------------------------------------------------------------------
// Send to the mail handler class
//---------------------------------------------------------------------
MailHandler mh = new MailHandler();
mh.SendMail(listRecipients, "Test Results " + tbName.Text, sb.ToString());
But I was getting the error...Gridview must be placed inside a form tag with runat=server. And of course it is, and the panel and the label are not throwing a similar error. I found this nifty fix:
public override void VerifyRenderingInServerForm(Control control)
{
return;
}
found it here: http://blogs.x2line.com/al/archive/2004/10/08/576.aspx
and it worked like a charm. I didn't spend more time investigating which controls require the fix, but if I see the error, I know where to start. Thanks Anatoly!
Subscribe to:
Post Comments (Atom)
10 comments:
Thanks for posting that workaround. I have been chasing my tail with that error all morning!
This worked like a charm. Thanks for sharing this.
marvelous, thanks a lot!! you may also use something like this:
public override void VerifyRenderingInServerForm(Control control)
{
if (control != this.gridViewControl) {
base.VerifyRenderingInServerForm(control);
}
}
Thank you. Very helpful.
cool man
thanks a lot
Cool , saved lot of time .
Thanks.. It's help me lots.
Thank you veryyyy much! it's realy worked like a charm!!!!
Brilliant dude,thanks a lot
Post a Comment