Web Page Organization
I have done a lot of reading on ASP.NET with VB and C#. Mostly, I have been reading ASP.NET unleashed. I am not clear on this general concept:
Can you convert an entire project and use it as an include in a web page? Basically, can you open up VS.NET, create a new project, and start coding? Then, in a web page that already exists, use that project in it.
What I am trying to do is seperate my page into sections. For example, I have a poll. I can get the poll to work using a code behind file. Im wondering if I can create a project with HTML and code behind, then include the enitre project into another web page. This way, if I had 5 web pages, all I would have to do is include the poll 5 times.
If the above isn't clear, here is a look at my general set up:
- include header.aspx
- include body.aspx
- include rightnavbar.aspx
- include footer.aspx
In rightnavbar, there is a poll. Inside the file rightnavbar.aspx, i would like to be able to include a poll "module". The problem with using a bunch of different code behinds is that every page is inside of index.aspx, and index can only have one code behind - this makes for to much code in one file.
So, any advice to point me in the right direction is appreciated. How would you organize a project like this?
I don't do any web based coding and no ASP, but normally, your setup would consist of different frames with different sources I think. There should be no need to put all your modules into one source file.
To include non-asp.net scripted files, you can just use:
Unfortunately, ASP.NET can't include other aspx files in each other. However, you can create user controls (like web components) that you can include in your files. So you can have a top user control, a bottom user control and your content in the middle. These user controls can output the neccesary html.
<% Response.WriteFile("file.html"); %>
You can do this with a function, as well. Just make a module (or static functions) that output the appropiate html.
Thanks for the replies. If anyone was curious, I ended up creating one project, and having multiple namespaces. One namespace, for example, is poll. My main codebehind page will call a function from Poll, and send it the selected index. I did this for user login, news, message board, etc.
Speedy, you mentioned you can't include aspx files inside one another. In my page, I used the following:
So far it works. Is this bad practice?
I think what you are using are server-side includes done on the server application. I recommend you use the Response.WriteFile() method instead if you are including other HTML files.