HTML Source

icemanind

Member
Joined
Mar 20, 2008
Messages
12
Programming Experience
5-10
Is there a way to get the HTML Source code of a processed ASP.NET server page? So, in other words, I have a file called default.aspx. The ASP.NET server processes the page, but before it transmits it to the client to be rendered, I want to be able to change the raw html code from VB.NET. I am assuming this is what the PreRender page event is for. Is this possible? In case your wondering what I'm trying to do, I'm using a 3rd party control from Infragistics called a WebDayView. However, I want to be able to dynamically add different icons to each day and the controls doesn't support it. So what I did was I marked each place, with text, where the image needs to go and my plan was to replace this "mark" I made with <img src=""> tags.
 
Last edited:
I'm pretty sure the order of things are Initialize Objects, ..., PreRender, Save ViewState, Render to HTML, Dispose.

During the Render method an HtmlTextWriter object is sent as a parameter and outputs HTML as a stream to the browser.

You'd need to override the Render event to send in the custom icons.
 
I meant to come back to this earlier, hopefully it's something you still need or someone else can make use of in the future.

VB.NET:
    <form id="form1" runat="server">
        <div>
            <!--Placeholder1-->
        </div>
    </form>

In testing I set up an area to replace content.

VB.NET:
Imports System.IO

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
        Dim output As TextWriter = New StringWriter()
        MyBase.Render(New HtmlTextWriter(output))
        writer.Write(output.ToString().Replace("<!--Placeholder1-->", "<p>I've replaced Placeholder1! Check my link to <a href=http://www.google.com>Google</a></p>"))
    End Sub
End Class

Doing a simple replace with the new HTML.
 
Last edited:
Back
Top