Creating a static ASP.NET page and a few other newbie questions

W

William Parker

OK, these questions are going to seem so basic that I am actually embarrased
to ask them but I really need the guideance. I've done some fairly complex
coding for years with class ASP and I'm very comfortable with it. However I
am new to ASP.NET and there are a few basic things I just don't get...

#1: Using VS.NET (original, 2002 release) how am I supposed to create a
basic, static ASP.NET page that just contains HTML and maybe some JavaScript
and no form? My choices of page types to create when I choose Project->Add
New Item do not show just a regular aspx page to create. I see a WebForm
page type, but I'm NOT looking to create a form with a code behind page,
just a plain old aspx page. There is a HTML page type. Basically I've been
using that and just renaming the page to .html to .aspx.

For example, let's say I just wanted to create a basic .aspx web page that
contained only static data like this:
<html>my content goes here</html>
I don't need a code behind and all that. I can use notepad to create it but
I'm trying to do everything from within VS.NET. Is my current approach for
this correct by just creating it as a HTML page type and renaming it? Or
should I be approaching this differently? For example, what are you
supposed to do for information only web pages where the content is static -
no db access needed etc?

#2: For content that needs to be included in every web page, like a footer -
how are you supposed to go about that? Is there a "include file" directive
like in classic ASP?

#3: Let's say I have helper "global" functions that I need to access from
many different aspx pages. In classic ASP I would just include a .inc file
from each page I needed to call the global functions from and define the
functions in the .inc file. What is the right technique for this with
ASP.NET?

I appreciate the whatever tips and guideance you guys have for me. Thank
you!!!

Bill
 
H

Hans Kesting

William Parker said:
OK, these questions are going to seem so basic that I am actually embarrased
to ask them but I really need the guideance. I've done some fairly complex
coding for years with class ASP and I'm very comfortable with it. However I
am new to ASP.NET and there are a few basic things I just don't get...

#1: Using VS.NET (original, 2002 release) how am I supposed to create a
basic, static ASP.NET page that just contains HTML and maybe some JavaScript
and no form? My choices of page types to create when I choose Project->Add
New Item do not show just a regular aspx page to create. I see a WebForm
page type, but I'm NOT looking to create a form with a code behind page,
just a plain old aspx page. There is a HTML page type. Basically I've been
using that and just renaming the page to .html to .aspx.

For example, let's say I just wanted to create a basic .aspx web page that
contained only static data like this:
<html>my content goes here</html>
I don't need a code behind and all that. I can use notepad to create it but
I'm trying to do everything from within VS.NET. Is my current approach for
this correct by just creating it as a HTML page type and renaming it? Or
should I be approaching this differently? For example, what are you
supposed to do for information only web pages where the content is static -
no db access needed etc?

If that is totally static, why isn't html a good choice? (one answer could be:
'so I don't have to change links in case it shouldn't be static anymore')
When you use a webform, you don't *need* to add code ...
#2: For content that needs to be included in every web page, like a footer -
how are you supposed to go about that? Is there a "include file" directive
like in classic ASP?

No "include". The asp.net equivalent is "webusercontrol". You define an ascx module
that you can then drag onto every page where you want it.
#3: Let's say I have helper "global" functions that I need to access from
many different aspx pages. In classic ASP I would just include a .inc file
from each page I needed to call the global functions from and define the
functions in the .inc file. What is the right technique for this with
ASP.NET?

You can define "classes" that you can use from every aspx/ascx (or other classes).
You might want to create a new project to hold these (type classlibrary).
The webproject needs a "reference" to this classlibrary-project before you can
use anything from that.
 
W

William Parker

If that is totally static, why isn't html a good choice? (one answer could
be:
'so I don't have to change links in case it shouldn't be static anymore')
When you use a webform, you don't *need* to add code ...

That is a good point. The reason is two fold - one we don't want to have
some pages .html and some .aspx. The other is that now that I think about
it, the page won't be *totally* static. In other words, it may set a cookie
or need a server environment variable, or may be completely static except
for having to use the web user control.

So in my case then, are you saying the correct approach is to create a
"webform" type page for every page, even for those pages that will not
contain any forms and buttons/controls/events and just leave the code behind
page blank? My concern there is that now I have two files for every web
page - the .aspx as well as its code behind. Couldn't that be a bit messy
maintenance-wise over time?
No "include". The asp.net equivalent is "webusercontrol". You define an ascx module
that you can then drag onto every page where you want it.

And then from various parts of my .aspx I call methods in the web user
control to force it to write out the html for a header or footer where
needed?
You can define "classes" that you can use from every aspx/ascx (or other classes).
You might want to create a new project to hold these (type classlibrary).
The webproject needs a "reference" to this classlibrary-project before you can
use anything from that.

Perfect. Thank you.

Bill
 
H

Hans Kesting

So in my case then, are you saying the correct approach is to create a
"webform" type page for every page, even for those pages that will not
contain any forms and buttons/controls/events and just leave the code behind
page blank? My concern there is that now I have two files for every web
page - the .aspx as well as its code behind. Couldn't that be a bit messy
maintenance-wise over time?

If you use Visual Studio, you don't need to worry, it keeps reasonably good
track of the files (3, there is also a resx file) that belong together.
And then from various parts of my .aspx I call methods in the web user
control to force it to write out the html for a header or footer where
needed?

Not exactly: these web user controls have their own eventhandlers,
like Page_Load etc.
The page doesn't need to know any specifics about that control
so you could completely rewrite it, without changing the pages
it's included in. The control knows how & when to generate html.

Hans Kesting
 

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

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top