Groups | Blog | Home
all groups > asp.net building controls > july 2005 >

asp.net building controls : Modify the HMTL generated in a user control


David
7/6/2005 5:46:20 PM
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

David
7/13/2005 10:07:10 AM
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


[quoted text, click to view]

intrader
7/18/2005 12:00:00 AM
[quoted text, click to view]
1 I woould write the Response and htmlt a buffer.
2. I write ths stuff useing XHTML.
3. Before you are ready to render, make your transformations ad required
and write the output stream.


AddThis Social Bookmark Button