473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HtmlTextWriter - send control via e-mail asp.net 2.0

I can't seem to get HtmlTextWriter / renderControl to work for sending a
control (html) in an e-mail messsage (VB.NET).
Keeps telling me that control needs to be in a form tag with runat server
(which it is)
Tried googling but only good for C# and classic asp.
Has anyone seen or has a solution??
Jul 4 '06 #1
4 4337
Hi,

James Page wrote:
I can't seem to get HtmlTextWriter / renderControl to work for sending a
control (html) in an e-mail messsage (VB.NET).
Keeps telling me that control needs to be in a form tag with runat server
(which it is)
Tried googling but only good for C# and classic asp.
Has anyone seen or has a solution??
I am struggling with that kind of problem too, in my case I attempt to
render the whole page to an external (static) html file.

Apparently, when the control is rendered, a few basic rules are checked.
For example, before the control is rendered, its FORM control must be
rendered. Also (and it's what I am trying to solve now), the FORM
control can be rendered only once. I am not sure if there is a method to
call to render controls to another writer without having these rules
throwing exceptions.

In your case, try to render the FORM control before you render the
child, maybe it'll work.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jul 5 '06 #2
Hi,

Laurent Bugnion wrote:
Hi,

I am struggling with that kind of problem too, in my case I attempt to
render the whole page to an external (static) html file.

Apparently, when the control is rendered, a few basic rules are checked.
For example, before the control is rendered, its FORM control must be
rendered. Also (and it's what I am trying to solve now), the FORM
control can be rendered only once. I am not sure if there is a method to
call to render controls to another writer without having these rules
throwing exceptions.

In your case, try to render the FORM control before you render the
child, maybe it'll work.

HTH,
Laurent
Update: I managed to render my page to the external file by overriding
the Page's Render method:

protected override void Render( HtmlTextWriter writer )
{
if ( Request.Form != null
&& Request.Form[ bnProduce.ClientID ] != null )
{
this.RenderPage();
writer.WriteLine( "It worked" );
writer.WriteLine( "<br /><a href=\""
+ this.Request.RawUrl + "\">back</a>" );
}
else
{
base.Render( writer );
}
}

The "trick" in my case was to comply to the rules, and writing the FORM
control only once in the same postback

Needs some cleaning, but the basic concept works.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jul 5 '06 #3
Thanks for the reply Laurent

Do you have an example in VB.net??

"Laurent Bugnion" wrote:
Hi,

Laurent Bugnion wrote:
Hi,

I am struggling with that kind of problem too, in my case I attempt to
render the whole page to an external (static) html file.

Apparently, when the control is rendered, a few basic rules are checked.
For example, before the control is rendered, its FORM control must be
rendered. Also (and it's what I am trying to solve now), the FORM
control can be rendered only once. I am not sure if there is a method to
call to render controls to another writer without having these rules
throwing exceptions.

In your case, try to render the FORM control before you render the
child, maybe it'll work.

HTH,
Laurent

Update: I managed to render my page to the external file by overriding
the Page's Render method:

protected override void Render( HtmlTextWriter writer )
{
if ( Request.Form != null
&& Request.Form[ bnProduce.ClientID ] != null )
{
this.RenderPage();
writer.WriteLine( "It worked" );
writer.WriteLine( "<br /><a href=\""
+ this.Request.RawUrl + "\">back</a>" );
}
else
{
base.Render( writer );
}
}

The "trick" in my case was to comply to the rules, and writing the FORM
control only once in the same postback

Needs some cleaning, but the basic concept works.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jul 5 '06 #4
Hi James,

James Page wrote:
Thanks for the reply Laurent

Do you have an example in VB.net??
Sorry, I don't do VB.NET anymore, but you should be able to translate
quite easily, because the methods and properties bear the same names.
What I do is:

- Check if the Request.Form property exists (it is null if this is a
GET, i.e. if the page is loaded for the first time), and if the
Request.Form property exists, I check if the ID of the button is present
in the request. If it is, then it means that the button was clicked.

The reason why I do this is that I need to check which button was
clicked before the page is rendered. If I use normal events, they will
be executed too later, after Page_Load is called.

- If the button ID is found, i.e. if the button was clicked, I use my
RenderPage method instead of using the base class' method. I just
noticed that I didn't copy the RenderPage method in my previous post,
see below.

- To avoid rendering the Form control twice (which causes the error), I
write simple code to the HtmlTextWriter (just a link) instead of calling
base.Render().

- If the button was not clicked, I call the Render method of the base
class, which will simply and normally render all the controls on the
page to the Response object.

The RenderPage method looks like this:

private void RenderPage()
{
HtmlTextWriter writer = null;

try
{
writer
= new HtmlTextWriter(
new StreamWriter(
"c:\\temp\\static.html", false ) );

foreach ( Control child in this.Controls )
{
child.RenderControl( writer );
}
}
catch ( Exception ex )
{
throw ex;
}
finally
{
if ( writer != null )
{
writer.Close();
}
}
}

This method is quite simple too: I create a new HtmlTextWriter which
will write to a Static file located at c:\temp\static.html (in the real
code I use properties to do that, but it doesn't matter).

Then I loop through all the controls on the page, and instead of
rendering them to the Response object, I render them to the static file
using the Writer I just created. The try/catch/finally is just to make
sure that the Writer is closed even if there is an error.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jul 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Greg Christie | last post by:
I think I have a somewhat unique situation here, so I thought I should post it for the few poor souls who run across it and try to google it like I did. First of all, I was getting the following...
4
by: phil_gg04 | last post by:
Dear Javascript Experts, I'm currently implementing Anyterm, a terminal emulator on a web page. It consists of an Apache module, some XmlHTTP and a bit of Javascript. The idea is to give you...
2
by: Foehammer | last post by:
I am using the standard .NET method of sending an email. My users will be filling out a web form with various pieces of information. I have created a control with properties that are the same as...
1
by: José Joye | last post by:
Hello, I'm playing around with dynamically loading user controls ...and having problems I created a really simple userControl (in fact contains a plain text box) and placed it into the...
1
by: Eric | last post by:
Hi, I have a strange behaviour with my Server Control. An easy one: public class SystemInfo : System.Web.UI.WebControls.WebControl { //protected override void Render(HtmlTextWriter output)
3
by: Jason Dean | last post by:
Hello, I have a simple asp:label control that I want to write some complicated HTML to. Currently I have this code and it works fine: myLable.Text = "<p>this is my text</p>" Bust as my...
2
by: daFou | last post by:
Hi All. All I want to do is get the HTML of a control on my page at postback into a string in my code behind. In ASP.NET 1.0 this used to be simple: Dim lStringWriter As...
7
by: Jonas | last post by:
Hi. I'm trying to develop a web custom control that uses a programmatically created treeview. My problem is that I get an exception when I try to render the control. With properties do I have to...
0
by: indiarocks | last post by:
I need to send control+C after sending a particular command on my ssh session. How do I achieve this using Python 2.3 with pexpect? I tried using conn_handle.sendline(chr(3)), but that doesn't...
0
by: shapper | last post by:
Hello, I am creating a class with a control. I compiled the class and used it on an Asp.Net 2.0 web site page. I can see the begin and end tags of my control (<oland </ol>) but somehow the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.