Unable to set a string to Include statement

T

tshad

In my User control, I tried to do this:
***************************************************************************
<Script runat="server">
Public ClientName As String = "<!-- #include file =
...\includes\StaffingHeaders.inc -->"

</Script>

<%=ClientName%>
****************************************************************************

This gives me:

Parser Error Message: Server includes are not allowed in server script
tags.


If I try to do it this way:
In my User control, I tried to do this:
***************************************************************************
<Script runat="server">
Public ClientName As String = "<!-- #" & "include file =
...\includes\StaffingHeaders.inc -->"

</Script>

<%=ClientName%>
****************************************************************************

It gives me nothing

If I do this:
***************************************************************************
<Script runat="server">
Public ClientName As String = "!-- #" & "include file =
...\includes\StaffingHeaders.inc -->"

</Script>

<%=ClientName%>
****************************************************************************
As I would expect, it displays:

"!-- #include file = ..\includes\StaffingHeaders.inc -->

But as soon as I add the "<", I get the error.

This should just be a string, why isn't it?

Tom
 
G

Guest

What in the world are you trying to do?
It looks like you want to add an include file in your page. Which, I think,
is still allowed in
ASP.NET for backward compatibility. But that's the only reason why it's
there, you should not be using in ASP.NET.

If you want just to have include file in your page just add
<!-- #include file ="...\includes\StaffingHeaders.inc"> OUTSIDE server script.

This line will be Parsed by ASP and hopefully .inc file will be executed.
But Response.Write which you were doing in your examples will simply send
that string to the browser.

My advise don't use includes in .NET, since it's really old 'classic' asp
feature. Instead adopt OO programming approach.
 
T

tshad

WebMatrix said:
What in the world are you trying to do?
It looks like you want to add an include file in your page. Which, I
think,
is still allowed in
ASP.NET for backward compatibility. But that's the only reason why it's
there, you should not be using in ASP.NET.

If you want just to have include file in your page just add
<!-- #include file ="...\includes\StaffingHeaders.inc"> OUTSIDE server
script.

This line will be Parsed by ASP and hopefully .inc file will be executed.
But Response.Write which you were doing in your examples will simply send
that string to the browser.

My advise don't use includes in .NET, since it's really old 'classic' asp
feature. Instead adopt OO programming approach.

Actually, that is what I am in the midst of doing now.

My question is why would the parser give me an error on setting up the
string?

If it is in quotes, why would it not accept it?

Isn't the following a valid string?

Public ClientName As String = "<!-- #include file =
....\includes\StaffingHeaders.inc -->"

Also, assuming I can set a variable to the inlude string, outside of the
Script tags, isn't:

<!-- #include file = ...\includes\StaffingHeaders.inc -->

the same as:

<%=ClientName%>.

I was under the impression (and I could be wrong) that <%ClientName%> would
be replaced with:

<!-- #include file = ...\includes\StaffingHeaders.inc -->

Am I wrong here?

Thanks,

Tom
 
G

Guest

You are missing 2 points:
1. Include file is a legacy asp feature, the replacement for includes in
..NET world are things like server-side user controls, and plain .NET Claasses.

2. If you absolutely must use includes then try to understand how web server
parses web pages.
Everything outside Server Script will be parsed as HTML and served to the
browser. So having
<%=ClientName%> will simply render whatever value that variable holds.
However having this text outside server side tags
<!-- #include file =" ....\includes\StaffingHeaders.inc" --> tells parser
that this is an include file that needs to be executed.

From what I am seeing, you're trying to execute certain piece of code
dynamically. I think you'll be better off investigating .NET features that
could accomplish your goal. In any case, if you provide more details on what
you're trying to accomplish perhaps someone could steer you to the right
direction.
 
T

tshad

WebMatrix said:
You are missing 2 points:
1. Include file is a legacy asp feature, the replacement for includes in
.NET world are things like server-side user controls, and plain .NET
Claasses.

2. If you absolutely must use includes then try to understand how web
server
parses web pages.
Everything outside Server Script will be parsed as HTML and served to the
browser. So having
<%=ClientName%> will simply render whatever value that variable holds.
However having this text outside server side tags
<!-- #include file =" ....\includes\StaffingHeaders.inc" --> tells parser
that this is an include file that needs to be executed.

From what I am seeing, you're trying to execute certain piece of code
dynamically. I think you'll be better off investigating .NET features that
could accomplish your goal. In any case, if you provide more details on
what
you're trying to accomplish perhaps someone could steer you to the right
direction.

Actually, I have 2 problems (but I will forgo the inability to set a string
to the include statement - which makes no sense at all).

What I am trying to do is create a general aspx page that has all my normal
processing, except for the top and bottom sections of the pages which are
the company logos, menus etc.

I want to be able go to different companies, have them give me their top
sections (headers) and bottom sections (footers). I would then include them
like so:

******************************************************************************************
<%@ Register TagPrefix="fts" TAgName="header"
src="..\includes\travacHeaders.ascx" %>
<%@ Register TagPrefix="fts" TAgName="footer"
src="..\includes\travacFooters.ascx" %>
<%@ Page Language="VB" trace="false" debug="true" AutoEventWireup="true"
ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script runat="server">
sub Page_load(s as object,e as eventargs)
end sub
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Home Page</title>

<!-- Clients Headers are displayed here -->
<fts:header id=ctl1 runat="Server" />

<!-- Our Content Starts Here -->
<form id="Form1" runat="server">
<input type="hidden" name="__SCROLLPOS" value="" />
<center>
<br>
</center>
</form>

<!-- Our Content Ends Here -->

<!-- Clients Footers are displayed here -->
<fts:footer id=cdl2 runat="Server" />
******************************************************************************************

The problem with the above code is that it works fine for only one client.
I don't want to create the above page for each client. I would have
travacHeaders.ascx for one client, staffersHeaders.ascx for another client,
etc.

Originally, I tried to set up a control to call different include files:

*******************************************************************************************
<Script runat="server">
Public ClientName As String = "<!-- #include file " & "=
...\includes\travacHeaders.inc -->"

</Script>

<%=ClientName%>
*******************************************************************************************

One of the problem is that ASP, won't let me set the string to the incude
statement (and you say this won't work anyway).

How do I set this up to call different controls (or include files)?

Thanks,

Tom
 
G

Guest

So you are using User Control (.ascx file). Why don't you program your
control to render different content based on the client logged into your
site? For example place image control where company logo should go, and store
image name + path for each client in AppSettings section of web.config file
like that:
<add key="Client1" value = "~/images/Client1Logo.gif" />
<add key="Client2" value = "~/images/Client2Logo.gif" />

In your Control you can retrieve logo path by the client name from a
webconfig file and set ImageUrl property of your logo image control Control
like this:

imgLogo.ImageURL =
Page.resolveURL(System.Configuration.ConfigurationSettings.AppSettings().Item(ClientName))

Similar techniques can be applied for other dynamic elements of your control.
to the include statement - which makes no sense at all

No it makes perfect sense. Think about it. What would happen if you did this:
Response.Write("<!--#include file=""somefile.inc"" -->")
????
 
T

tshad

WebMatrix said:
So you are using User Control (.ascx file). Why don't you program your
control to render different content based on the client logged into your
site? For example place image control where company logo should go, and
store
image name + path for each client in AppSettings section of web.config
file
like that:
<add key="Client1" value = "~/images/Client1Logo.gif" />
<add key="Client2" value = "~/images/Client2Logo.gif" />

In your Control you can retrieve logo path by the client name from a
webconfig file and set ImageUrl property of your logo image control
Control
like this:

imgLogo.ImageURL =
Page.resolveURL(System.Configuration.ConfigurationSettings.AppSettings().Item(ClientName))

Similar techniques can be applied for other dynamic elements of your
control.

That is what I was looking for. I just need to look at this closer to
understand what you are doing.
No it makes perfect sense. Think about it. What would happen if you did
this:
Response.Write("<!--#include file=""somefile.inc"" -->")
????

You're right. I never noticed the quotes before. Brain fade.

Thanks,

Tom.
 

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

Top