Copy HTM file contents to InnerHtml

A

AAaron123

In the aspx:
<%@ MasterType VirtualPath="~/Main.master" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="RightCPH">
<div runat="server" style="overflow: auto;" id="History_Parish">
This text gets replaced</div>
</asp:Content>

The reason for the text "This text gets replaced" is that I copy new text to
InnerHtml

In the code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Master.CopyToControlInnerHtml("History\Parish.htm", History_Parish)
End Sub

In the master:
Public Sub CopyToControlInnerHtml(ByVal filename As String,
ByVal ctl As HtmlGenericControl)

Dim fileNameIn As String = Session("TopDirectory") & filename
Dim sr As System.IO.StreamReader
Dim strContents As String = ""
If System.IO.File.Exists(fileNameIn) Then
sr = System.IO.File.OpenText(fileNameIn)
strContents += sr.ReadToEnd()
sr.Close()
Dim pos1 As Integer = strContents.IndexOf("<body")
Dim bodyText As String = strContents.Substring(pos1)
Dim pos2 As Integer = bodyText.IndexOf(">") 'Find end of <body ...>

Dim bodyText2 As String = bodyText.Substring(pos2 + 1).
Replace("</body>", "").Replace("</html>", "")

ctl.InnerHtml = bodyText2
End If
End Sub

As you see I copy the text inside the body elements to InnerHtml.
Seems kind of kludgy to me.
Is there a better way?


Thanks in advance

BTW
Do most Asp.Net developers use .HTM or .HTML??
 
A

AAaron123

Actually I do use iframe in other places where I want the file's content to
display as it is.
I should have mentioned that I allow the user to choose the effective
stylesheet and I want it to effect the text from the files I copy.
That is, if the user selects a black background style (effects text color,
etc) I want that to be the style for the file's contents copied to
InnerHtml.

Thanks
 
H

Hillbilly

As I recall all of Microsoft's IDEs use the .htm as the default for an HTML
page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top