Wednesday, January 7, 2015

how to change the html content of controls rendering/output

let's say you have a textbox ABC. and for that textbox you want the append some strings in it

ABC.SetRenderMethodDelegate(Sub(h As HtmlTextWriter, c As Control)

h.Write("Hello Textbox!")

end sub)

Some controls won't work, such as because they don't implement Render function. Solution is to wrap these kinds of control inside a Placeholder and set the SetRenderMethodDelegate to the Placeholder instead

Example : Let's say you want to append the string " Good Bye" in the output of xml web control

Code Front

< asp:placeholder id="p" runat="server" >

 < asp:xml runat="server" id="x" transformsource="sheet.xslt" />

< / asp:placeholder >

Code Behind

x.DocumentSource = "Some Xml"

p.SetRenderMethodDelegate(Sub(h As HtmlTextWriter, c As Control)

Dim sb As New Text.StringBuilder
Dim tw As New System.IO.StringWriter(sb)
Dim htmlTW As New HtmlTextWriter(tw)
               h.write(sb.ToString() & " - Good Bye ")

end sub)

No comments: