Can a control produce html?

A

Adam Smith

Hi,

Hopefully someones come across this...

I've a page that dynamically generates some content. Part of this is a
series of user controls.
_______
|___x___|
|___x___|
|___x___|
|___x___| fig1
x: these are user controls

Now... if I do a view source, all I get is the table that houses the user
controls. I need to know the HTML that was generated, as these will later
be used in marketing.
So is it possible for a user control to squirt back pure html?

Thanks in advance!
 
J

John Saunders

Adam Smith said:
Hi,

Hopefully someones come across this...

I've a page that dynamically generates some content. Part of this is a
series of user controls.
_______
|___x___|
|___x___|
|___x___|
|___x___| fig1
x: these are user controls

Now... if I do a view source, all I get is the table that houses the user
controls. I need to know the HTML that was generated, as these will later
be used in marketing.
So is it possible for a user control to squirt back pure html?

I'm not sure what you mean. The only thing controls generate _is_ html!
 
A

Adam Smith

Forgive me, I was rather tired when I wrote that.

The reason I couldn't see it in the source was because smartnav was on and I
hadn't realised.

Ok that aside, I'm still after the html of a portion of the page.

so here goes:

<page start>

Textboxes
<div>
_______
|___x___|
|___x___|
|___x___|
|___x___| <--- this is a table, the 'X' represents some user controls
</div>
A textarea

<end of page>

So, I enter some information in the textboxes. This info is passed to the
user controls, which then change accordingly.
The textarea takes contains a copy of all the HTML in the div container.

So this is presumably an event sequence problem. How would I go about
capturing the HTML generated by these controls?

Thanks in advance,
Adam Smith
 
J

John Saunders

Adam Smith said:
Forgive me, I was rather tired when I wrote that.

The reason I couldn't see it in the source was because smartnav was on and I
hadn't realised.

Ok that aside, I'm still after the html of a portion of the page.

so here goes:

<page start>

Textboxes
<div>
_______
|___x___|
|___x___|
|___x___|
|___x___| <--- this is a table, the 'X' represents some user controls
</div>
A textarea

<end of page>

So, I enter some information in the textboxes. This info is passed to the
user controls, which then change accordingly.
The textarea takes contains a copy of all the HTML in the div container.

So this is presumably an event sequence problem. How would I go about
capturing the HTML generated by these controls?

Let me make sure I've got this right. You want the output of the user
controls to be placed within the TextArea? Do you also want that output to
be sent to the user's browser, or do you only want it to appear inside of
the TextArea?

You might have some luck by using a Panel control instead of a div. You
would then override the Render method of the page. In that method, you could
create an HtmlTextWriter which outputs to a string, then call
panel.RenderControl(stringHtmlWriter) to capture the HTML. You would then
have to find some way to get that string to render inside of your TextArea.
Also, if you want the page to render normally, you'd then have to call the
base class Render method.

This is all quite unusual. Is this really what you want, or have I
misunderstood?
 
A

Adam Smith

Hi John,

thanks for replying...

Heres what I'm trying to acheive.
This is for an e-mail marketing newsletter. The user enters the product
ID's in the textboxes at the top of the page (along with layout and some
other details). These are sent to multiple instances of the user control
which displays the product in question. This is all graphically displayed
in a Panel, so the user can see what the e-mail newsletter will look like.
This all works fine.

The Panel's html is grabbed via a htmltextwriter and deposited in the
textarea, this is so any manual modifications can be made and later saved to
a database for sending at a later date.

This works partially, the user controls HTML is not being grabbed. I
presume this is due to the calling of them happening after I grab the panels
html.

So where in the page life cycle do I need to grab the panels html in order
to include the html of the user controls?

Thanks in anticipation,
 
J

John Saunders

Adam Smith said:
Hi John,

thanks for replying...

Heres what I'm trying to acheive.
This is for an e-mail marketing newsletter. The user enters the product
ID's in the textboxes at the top of the page (along with layout and some
other details). These are sent to multiple instances of the user control
which displays the product in question. This is all graphically displayed
in a Panel, so the user can see what the e-mail newsletter will look like.
This all works fine.

The Panel's html is grabbed via a htmltextwriter and deposited in the
textarea, this is so any manual modifications can be made and later saved to
a database for sending at a later date.

This works partially, the user controls HTML is not being grabbed. I
presume this is due to the calling of them happening after I grab the panels
html.

So where in the page life cycle do I need to grab the panels html in order
to include the html of the user controls?

Adam,

HTML is only generated in the Render method. The output of the user controls
simply does not exist before the Render method of the user controls has
executed.

At the same time, you have the problem that you want to fill the textarea on
the same page with HTML generated from controls on the page. I don't think
you're going to get anywhere with that. If I were you, I'd look into some
client-side manipulations. HTML is all that the client side sees, so the
HTML will certainly be there for the client to manipulate.

One way you could do this would be to have an Edit button associated with
each panel. When the button is clicked, client-side script could copy
panel.InnerHTML into the TextArea. You could also pop up a separate window
with the HTML if you wanted.

If you can limit yourself to Internet Explorer, you could use some of the
content editing features of IE. See
http://msdn.microsoft.com/library/d.../browser/mshtml/mshtml_editing_node_entry.asp for far too much information on this. Also, my
favorite "Custom Controls" book has an example ASP.NET HTMLEdit control in
chapter 13. See "Developing Microsoft® ASP.NET Server Controls and
Components" from Microsoft Press, by Nikhil Kothari and Vandana Datye
(http://www.microsoft.com/mspress/books/5728.asp). Source code is provided.

I hope this helps you some. If it does, be sure to let us know - I needed
something like this at one time but punted because I couldn't get it done
quickly enough.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top