Conditioning include files ?

  • Thread starter Thread starter Mark Fitzpatrick
  • Start date Start date
M

Mark Fitzpatrick

Not like this. Include file processing is done BEFORE any script on the page
is run. It needs to be becuase most include files contain code that needs to
be part of the page.

In ASP.Net however, you do have lots of other options. For example,
encapsulating the content in a user control then adding the control to the
page, or a placeholder in the page like

if(condition1)
myPlaceholder.controls.add(myControl1);
else if (condition2)
myPlaceholder.controls.add(myControl2);

etc...
There are tons of different ways to do this, but SSI is not the way to
go if you need conditional includes because the include is always before any
script that can be used for conditional programming.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Include Files are generally not used, as they are not object-oriented.
Secondly, includes are pre-processor instructions, and it has never been
possible to use them conditionally. I think you need to use User Controls
instead, and you can conditionally add or remove them from the page.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.
 
I want to condition what include files are included in an web page (.aspx).
Something like:

if (condition1)
{
<!-- #Include File='file1.htm' -->
}
else if (condition2)
{
<!-- #Include File='file2.htm' -->
}
else
{
<!-- #Include File='file3.htm' -->
}

Is this posible in ASP.NET ?
What is the correct way to write this code ?
 
It's very strange what you are trying to do. But I suggest
you to read your HTML files with the System.IO namespace
(very simple). and then display the content of one of your
seleted file in a asp:placeholder.

if (condition1)
{
// read 'file1.htm' with system.io functions (you will
find many example in msdn)
placeHolder.controls.add(new litteral(<your file
content as string>)

}
else if (condition2)
{
<!-- #Include File='file2.htm' -->
}
else
{
<!-- #Include File='file3.htm' -->
}
 
Andre,

I think what you want to do will work just fine. You could use a combination
of dynamically loaded user controls and a placeholder tag to do exactly what
you want.

My own website is a single page into which user controls (the new include
file) are loaded into a main content area using a placeholder. I have the
sample code of how to do so in the site's code library. Just go to
www.aboutfortunate.com and then click the code library link. Use the search
box there to search for: "Dynamically load user control" or something
similar and you'll find the code you need to do this.

If you have any questions about it feel free to email me.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
My problem:

I have a page (aspx) that contains, among other things, a table cel (<td>)
in which I have to display the contents of 1 of 3 files that contain HTML
code, that are stored on the disk, depending on which button the user
clicks.

At first I thought that using include files would be the best solution, but
it seems not.

Anyone knows what would be the easyest way to do this ?

(I have been programing php and windows forms up until now and this is my
first project with web forms so I don't have much experience with this)
 
My problem:

I have a page (aspx) that contains, among other things, a table cel (<td>)
in which I have to display the contents of 1 of 3 files that contain HTML
code, that are stored on the disk, depending on which button the user
clicks.

At first I thought that using include files would be the best solution, but
it seems not.

Anyone knows what would be the easyest way to do this ?

(I have been programing php and windows forms up until now and this is my
first project with web forms so I don't have much experience with this)
 
Back
Top