Modify the HMTL generated in a user control

D

David

Hi all,

I have spent ages trying to work this out... I have searched google for ages
with different search criteria, tried various methods, all to no avail.

I am dynamically placing user control onto the page. Now, the page has a
"Text Only" link, so I have to modify the output of the user control to
remove any graphics.

I think I can do this with a usercontrol that doesn't have any form
elements, but as soon as a form item is met, I get an error that the element
must be inside a form tag.

I have...
System.Text.StringBuilder SB = new System.Text.StringBuilder();

System.IO.StringWriter SW = new System.IO.StringWriter(SB);

HtmlTextWriter UCText = new HtmlTextWriter(SW);

Control myForm = Page.FindControl("Form1");

Control myControl = Page.LoadControl(ResolveUrl("~" +
post.CustomProperties["ApplicationName"].Value));

//myForm.Controls.Add(myControl);

//myControl.RenderControl(UCText);

UCPH.Controls.Add(myControl);

UCPH.RenderControl(UCText);

UCPH.Controls.Clear();

UCPH.Controls.Add(new LiteralControl(SB.ToString()));

No matter which way I try it, it always breaks on the RenderControl.

I have to get this working. I don't mind wether it is in the UserControl
itself, or on the outside of the control.

All help is appreciated.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

I guess this is a difficult one to answer...

I had a thought about it though. Rather than trying to edit the rendered
usercontrol, I could render the final output page. Maybe this will be an
easier question to answer.

Once the page has been built up, how do I then edit the output before it
being sent to the browser? I have to make a text only page, so removing all
the image tags.

If this is still too difficult, then how about a piece of code that will
cycle through all the controls in a user control, if it finds any image
controls, remove them. (visible=false). This still leaves me with one other
issue, if I use the plain HTML image control (or input type image) that is
not runat=server, that will likely get left on. I need to remove all.

Best regards,
Dave Colliver.
http://www.LeicesterFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top