Executing a var within an aspx .inc file?

C

CES

All,
How do you write out a variable in a ASPX .inc?? I've used the following in
my code and it worked until I changed the date & MyWebSite, to a server side
write... is there any way of getting this to work within an inc file
structure? Thanks in advance. - CES
<%
Response.WriteFile("Yourfile.FileExtension");
%>
----- Yourfile.FileExtension ------
<div id="copyright">
Copyright <%=DateTime.Now.Year.ToString()%> - <%=MyWebSite%> - All rights
reserved.
<br />Use of this site signifies the users complete agreement to all terms,
contained
<br />&amp; described within the Terms of Use page (Updated July 31, 2008)
</div>
 
C

Cowboy \(Gregory A. Beamer\)

Why create include files in ASPX. It is much easier to derive from the Page
class and have your pages derive from that class. You can then have
something the same in every page that needs it.

There are other ways to set up global FUD, of course. I am not sure #Include
is my first option. It is probably my last.
 
C

CES

Thanks for not answering my question... I'm just switch over to .net from
classic asp and as much as possible I'm trying to take small steps with
concepts I've used in the past and what you just stated doesn't mean
anything to me... yet!
 
M

Michael Starberg

CES said:
Thanks for not answering my question...

- I'd say he did.
I'm just switch over to .net from classic asp and as much as possible I'm
trying to take small steps with concepts I've used in the past

- Maybe that is your problem
and what you just stated doesn't mean anything to me... yet!

- So it is Gregorys fault you don't understand? Hmm..

//Michael Starberg
 
C

Cowboy \(Gregory A. Beamer\)

CES said:
Thanks for not answering my question...

I did answer your question. You did not give me a context to go from, so I
made an incorrect assumption.
I'm just switch over to .net from classic asp and as much as possible I'm
trying to take small steps with concepts I've used in the past and what you
just stated doesn't mean anything to me... yet!

Now I have a context.

ASP is inline coded. It is interpreted one line at a time. ASP.NET is
compiled. This is your first paradigm shift.

You can do

<%
//code here
%>

in ASP.NET, but it is not advised. You are better to bind than to write out
stuff.

For example, you want a copyright date. Here is your old code:

<div id="copyright">
Copyright <%=DateTime.Now.Year.ToString()%> - <%=MyWebSite%> - All rights
reserved.
<br />Use of this site signifies the users complete agreement to all terms,
contained
<br />&amp; described within the Terms of Use page (Updated July 31, 2008)
</div>

To do this in .NET, you have three choices:

1. Use a class derived from page
2. Use a master page
3. User a control

The master page is probably the best option, if this is all you are doing,
but it is not something you can do to a page without altering it quite a
bit. With the class option, you can pull your ASP tags and with minor
alteration have the page running (it may not do everything the ASP does, but
it will display the copyright).

The user control encapsulates the logic, but you will have to drag it on
every page, which is why the master is so important.

Which of the options you ultimately chose depends on where you want to go.
The best replacement for .inc is a derived class. The best option, long
term, is a master page. If you feel you might use this in multiple sites, a
user control (or even a compiled server control) may be a better option.
 

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,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top