HighTechTalks DotNet Forums  

ASP.NET equivelant for include files that won't cause problems

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss ASP.NET equivelant for include files that won't cause problems in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Nathan Sokalski
 
Posts: n/a

Default ASP.NET equivelant for include files that won't cause problems - 03-25-2009 , 04:18 PM






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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/



Reply With Quote
  #2  
Old   
Mel Weaver
 
Posts: n/a

Default Re: ASP.NET equivelant for include files that won't cause problems - 03-26-2009 , 11:55 AM






Can you use a Literal control and insert the file with the code behind?


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote

Quote:
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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/




Reply With Quote
  #3  
Old   
Nathan Sokalski
 
Posts: n/a

Default Re: ASP.NET equivelant for include files that won't cause problems - 03-26-2009 , 04:10 PM



I could, but if you read my original posting I mention that the problem is
not finding a way to put the info there, but finding an inline way to do it
that does not require editing any other files. Using a Literal would require
adding code to the codebehind to add the text. I know that I am turning down
a very simple way to add the file, but unfortunately the people that will be
using the code are still to ASP.NET illiterate to add code to more than one
place (I have to give them 1 line of code that they can copy and paste into
all of their standalone *.aspx files and all of their *.master pages.) Any
other ideas?
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/

"Mel Weaver" <MelRemoveSpam (AT) Insdirect (DOT) com> wrote

Quote:
Can you use a Literal control and insert the file with the code behind?


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote in message
news:ugiwjeZrJHA.4592 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/






Reply With Quote
  #4  
Old   
gerry
 
Posts: n/a

Default Re: ASP.NET equivelant for include files that won't cause problems - 03-27-2009 , 06:42 AM



so create a simple custom control that has a single property , say "Source"
, that you drop on a page as a tag, call it say Include and away you go :

<sok:Include Source="~/MyFile.txt" />

Should only take a few minutes to code up.




"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote

Quote:
I could, but if you read my original posting I mention that the problem is
not finding a way to put the info there, but finding an inline way to do it
that does not require editing any other files. Using a Literal would
require adding code to the codebehind to add the text. I know that I am
turning down a very simple way to add the file, but unfortunately the
people that will be using the code are still to ASP.NET illiterate to add
code to more than one place (I have to give them 1 line of code that they
can copy and paste into all of their standalone *.aspx files and all of
their *.master pages.) Any other ideas?
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/

"Mel Weaver" <MelRemoveSpam (AT) Insdirect (DOT) com> wrote in message
news:uwsAGwjrJHA.772 (AT) TK2MSFTNGP05 (DOT) phx.gbl...
Can you use a Literal control and insert the file with the code behind?


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote in message
news:ugiwjeZrJHA.4592 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/








Reply With Quote
  #5  
Old   
Patrice
 
Posts: n/a

Default Re: ASP.NET equivelant for include files that won't cause problems - 03-27-2009 , 09:24 AM



Also #include is still supported in APS.NET :

http://msdn.microsoft.com/en-us/library/3207d0e3(VS.71).aspx

Not sure the overall goal but if this is to skin an application perhaps
something more elaborated...

--
Patrice


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> a écrit dans le message de groupe
de discussion : Oo4Xw#lrJHA.5356 (AT) TK2MSFTNGP03 (DOT) phx.gbl...
Quote:
I could, but if you read my original posting I mention that the problem is
not finding a way to put the info there, but finding an inline way to do
it that does not require editing any other files. Using a Literal would
require adding code to the codebehind to add the text. I know that I am
turning down a very simple way to add the file, but unfortunately the
people that will be using the code are still to ASP.NET illiterate to add
code to more than one place (I have to give them 1 line of code that they
can copy and paste into all of their standalone *.aspx files and all of
their *.master pages.) Any other ideas?
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/

"Mel Weaver" <MelRemoveSpam (AT) Insdirect (DOT) com> wrote in message
news:uwsAGwjrJHA.772 (AT) TK2MSFTNGP05 (DOT) phx.gbl...
Can you use a Literal control and insert the file with the code behind?


"Nathan Sokalski" <njsokalski (AT) hotmail (DOT) com> wrote in message
news:ugiwjeZrJHA.4592 (AT) TK2MSFTNGP06 (DOT) phx.gbl...
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.
--
Nathan Sokalski
njsokalski (AT) hotmail (DOT) com
http://www.nathansokalski.com/







Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.