Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Modifying content of RenderControl

Reply
Thread Tools

Modifying content of RenderControl

 
 
Samuel Hon
Guest
Posts: n/a
 
      04-29-2004
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

Sam
 
Reply With Quote
 
 
 
 
ccallen
Guest
Posts: n/a
 
      04-29-2004
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

"Samuel Hon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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
>
> Sam



 
Reply With Quote
 
 
 
 
Samuel Hon
Guest
Posts: n/a
 
      04-29-2004
Hi there

Thanks for the reply.

"ccallen" <(E-Mail Removed)> wrote in message news:<#(E-Mail Removed)>...
> 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().


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
any one have any examples or ideas?
 
Reply With Quote
 
Fred Hirschfeld
Guest
Posts: n/a
 
      04-30-2004
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



"Samuel Hon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi there
>
> Thanks for the reply.
>
> "ccallen" <(E-Mail Removed)> wrote in message

news:<#(E-Mail Removed)>...
> > 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().
>
> 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
> any one have any examples or ideas?



 
Reply With Quote
 
Samuel Hon
Guest
Posts: n/a
 
      04-30-2004
Thanks Fred

Thats just the ticket

"Fred Hirschfeld" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
>
>
>
> "Samuel Hon" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > Hi there
> >
> > Thanks for the reply.
> >
> > "ccallen" <(E-Mail Removed)> wrote in message

> news:<#(E-Mail Removed)>...
> > > 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().
> >
> > 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
> > any one have any examples or ideas?

 
Reply With Quote
 
Samuel Hon
Guest
Posts: n/a
 
      05-04-2004
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.

Any ideas? Cheers
 
Reply With Quote
 
Fred Hirschfeld
Guest
Posts: n/a
 
      05-06-2004
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

"Samuel Hon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.
>
> Any ideas? Cheers



 
Reply With Quote
 
Samuel Hon
Guest
Posts: n/a
 
      05-06-2004
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

"Fred Hirschfeld" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Render vs RenderControl George Ter-Saakov ASP .Net 3 10-25-2006 10:43 AM
form RenderControl doesn't work in win app Ken Boone via .NET 247 ASP .Net 1 09-22-2004 02:13 PM
Datagrid to Excel - error - rendercontrol Steve Chatham ASP .Net 0 02-23-2004 05:23 PM
Code to export html table (.RenderControl) doesn't like sort headings? Kathy Burke ASP .Net 2 11-11-2003 11:23 PM



Advertisments