Reset render method flag ????
-
For some reason, I need to call base.Render (HtmlTextWriter writer) for serveral times, but with different writer. However, I got this error - "Can only have one form tag for a Page". It seems that the ASP.NET system has a flag determining how many times we call the render method. So I am here to ask - Is there a way to reset the render method, so I can call it many times i want ??
-
For some reason, I need to call base.Render (HtmlTextWriter writer) for serveral times, but with different writer. However, I got this error - "Can only have one form tag for a Page". It seems that the ASP.NET system has a flag determining how many times we call the render method. So I am here to ask - Is there a way to reset the render method, so I can call it many times i want ??
There is no such flag. If you post the code, I can see what the problem is.
-
There is no such flag. If you post the code, I can see what the problem is.
protected override void Render(HtmlTextWriter writer) { foreach (string email in emailList) { StringBuilder _buffer = new StringBuilder (); StringWriter swa = new StringWriter (_buffer); HtmlTextWriter htmlWriter = new HtmlTextWriter (swa); /* Change some content in the Page */ ... base.Render (htmlWriter); MailMessage mail = new MailMessage (); mail.To = email; mail.Body = _buffer.ToString (); mail.BodyFormat = MailFormat.Html; SmtpMail.SmtpServer = "192.168.0.1"; SmtpMail.Send (mail); htmlWriter.Close (); } } Here is the code that get problem. The base.Render will not run twice !!! PS. Here is some aritcle talking about the flag http://msdn.microsoft.com/msdnmag/issues/03/05/CuttingEdge/default.aspx[^]
-
protected override void Render(HtmlTextWriter writer) { foreach (string email in emailList) { StringBuilder _buffer = new StringBuilder (); StringWriter swa = new StringWriter (_buffer); HtmlTextWriter htmlWriter = new HtmlTextWriter (swa); /* Change some content in the Page */ ... base.Render (htmlWriter); MailMessage mail = new MailMessage (); mail.To = email; mail.Body = _buffer.ToString (); mail.BodyFormat = MailFormat.Html; SmtpMail.SmtpServer = "192.168.0.1"; SmtpMail.Send (mail); htmlWriter.Close (); } } Here is the code that get problem. The base.Render will not run twice !!! PS. Here is some aritcle talking about the flag http://msdn.microsoft.com/msdnmag/issues/03/05/CuttingEdge/default.aspx[^]
When I test with the code I got the same error. I dont know the problem. In this case you can workaround this, if have understand your code correctly. I hope you want to email the page content to a set of email (the same content). Why u r getting the html to be sent in the email in the loop. Get the content before loop as string and then send it to all. Now the n time (loop) rendering reduced to 2 times (one for email and one for page rendering). Instead of calling base.Render for page rendering, you just use Response.Redirect to recreate the page. Hope this will help.
-
When I test with the code I got the same error. I dont know the problem. In this case you can workaround this, if have understand your code correctly. I hope you want to email the page content to a set of email (the same content). Why u r getting the html to be sent in the email in the loop. Get the content before loop as string and then send it to all. Now the n time (loop) rendering reduced to 2 times (one for email and one for page rendering). Instead of calling base.Render for page rendering, you just use Response.Redirect to recreate the page. Hope this will help.
-
How about the email content that sent to everyone is not exactly the same ? Does it mean that you need to render everytimes you change he content ?!!!
You are sending the page content as email for many ids. Thats what I understand from ur code. If you want to change the content, change the content of the html string in the loop. Hope I get your question correctly.