N
Nathan Sokalski
I need to come up with an easy way to insert the contents of a text file
into an *.aspx or *.master file, using some kind of inline code the way
include files used to be used with Classic ASP (My boss wants something that
I can simply say "Put this code in the head of the html", since half the
webteam is not yet very familiar with ASP.NET). My original attempt was:
<%=System.IO.File.ReadAllText(Server.MapPath("~/MyFile.txt"))%>
This worked fine for a while on most pages, but then I came across a page
that complained about something to do with not being able to add Controls to
ControlsCollection because the page contained a code block. Most of the
solutions I found while doing some research on this suggested using a
databinding expression using <%# %>. The only problem with doing this is
that you must call Page.Header.DataBind() before it is evaluated, which
would require either:
1. A code block, which I cannot use because it causes the error
2. Adding code to the codebehind or a <script runat="server"></script>,
which my boss does not want me to ask everyone to do
I think writing a custom control would be nice, but once again that would be
more than my boss would be willing to let me ask everyone else to do. Any
ideas? Thanks.
into an *.aspx or *.master file, using some kind of inline code the way
include files used to be used with Classic ASP (My boss wants something that
I can simply say "Put this code in the head of the html", since half the
webteam is not yet very familiar with ASP.NET). My original attempt was:
<%=System.IO.File.ReadAllText(Server.MapPath("~/MyFile.txt"))%>
This worked fine for a while on most pages, but then I came across a page
that complained about something to do with not being able to add Controls to
ControlsCollection because the page contained a code block. Most of the
solutions I found while doing some research on this suggested using a
databinding expression using <%# %>. The only problem with doing this is
that you must call Page.Header.DataBind() before it is evaluated, which
would require either:
1. A code block, which I cannot use because it causes the error
2. Adding code to the codebehind or a <script runat="server"></script>,
which my boss does not want me to ask everyone to do
I think writing a custom control would be nice, but once again that would be
more than my boss would be willing to let me ask everyone else to do. Any
ideas? Thanks.