all groups > asp.net building controls > april 2004 >
You're in the

asp.net building controls

group:

Modifying content of RenderControl



Modifying content of RenderControl noreply NO[at]SPAM samuelhon.co.uk
4/29/2004 3:58:09 AM
asp.net building controls: Hi

I'm currently using

Public Class Template
Inherits Control

Protected Overrides Sub Render(Writer As HtmlTextWriter)
Writer.WriteLine ("...")
Controls(1).RenderControl(Writer)
Writer.WriteLine ("...")
End Sub

End Class

in one of my controls.

I would like to modify the content in the control using regular
expressions. Does any one have any suggestions on how to do this?
Thanks

Re: Modifying content of RenderControl ccallen
4/29/2004 8:50:05 AM
Rather then writing each chunk to Writer.WriteLine(), build the string up in
a string object (or stringbuilder). Once the string has been constructed
(including regular expression operations), pass it to Writer.Writeline().

ccallen

[quoted text, click to view]

Re: Modifying content of RenderControl noreply NO[at]SPAM samuelhon.co.uk
4/29/2004 2:33:37 PM
Hi there

Thanks for the reply.

[quoted text, click to view]

I thought about this, but the text i need to perform regex operations
on, is in the control and this only accepts HTMLTextWriters. I havent
yet discovered if I can manipulate the HTML in the text writer. Does
Re: Modifying content of RenderControl Fred Hirschfeld
4/29/2004 6:45:20 PM
I have not done this but you should be able to create a StringWriter object
and use that to create the HtmlTextWriter for memory writing. Then you can
use the text is has to do your regular expression stuff...

Note... this is C#...

StringBuilder sb = new StringBuilder()
StringWriter sw = new StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);

Controls[1].RenderControl(htw);

htw.Close();
sw.Close();

// use your Regular Expression code here...

Fred



[quoted text, click to view]

Re: Modifying content of RenderControl noreply NO[at]SPAM samuelhon.co.uk
4/30/2004 2:26:07 AM
Thanks Fred

Thats just the ticket

[quoted text, click to view]
Re: Modifying content of RenderControl noreply NO[at]SPAM samuelhon.co.uk
5/4/2004 6:05:50 AM
OK, I'm experiencing something strange now. The aspx rendering is
working in reverse order

In my aspx page, i'm using:

<SH:Template runat="server">
<SH:Container id="SH2" runat="server">
<B>Render something here.</B>
<% Response.Write("Something going on here.") %>
</SH:Container>
</SH:Template>

In my control, I'm using:

Namespace SH
Public Class Template
Inherits Control

Protected Overrides Sub Render(Writer As HtmlTextWriter)
Writer.WriteLine ("...")
Writer.WriteLine(ReplaceText(Controls(1),strText))
Writer.WriteLine ("...")
End Sub

Public Function ReplaceText(objControl As Control, _
strText As String) As String

Dim objStringWriter As New System.IO.StringWriter()
Dim objHTMLWriter As New HtmlTextWriter(objStringWriter)

objControl.RenderControl(objHTMLWriter)

Dim str As String = objStringWriter.ToString()
Return str.ToString()
End Function

End Class
End Namespace

What I'm finding is that my HTML page is coming up as

Something going on here. Render something here.

instead of

Render something here. Something going on here.

Re: Modifying content of RenderControl Fred Hirschfeld
5/5/2004 10:22:24 PM
I have not done something like this but I am assuming that you cannot use
the inline code to do what you are expecting as I think the inline will get
executed and sent to the stream before your processing as appears to happen.

Then your control evaluates and renders its content. I would expect that you
might want to have a custom tag that can contain the information you would
like to write or add it as an attribute to the Container tag.

Also, do you need the runat=server for the sub-tag SH:Container?

Fred

[quoted text, click to view]

Re: Modifying content of RenderControl noreply NO[at]SPAM samuelhon.co.uk
5/6/2004 6:13:05 AM
Hi Fred

I'm afriad the third party assemblies I'm using dont allow me to place
my content in the attributes. To get around this, I've placed all my
content in the script <% %>. Not the most efficient for static
content, but its a workaround until I find a nice solution

Thanks for the help

Sam

PS You're right about the second runat=server, its not necessary

[quoted text, click to view]
AddThis Social Bookmark Button