Andy
Andy

Reputation: 1163

Including html parts in asp.net

I am writing web site using ASP.net, and I want to seperate my pages into some logical HTML parts (menus, panels, etc.).
When it comes to parts that have a server logic, the obvious solution is to use UserControl, but most of the parts on my site, have client side logic only, i.e javascript and HTML.
Recently I found out that it's possible to include parts by using the code:
<% Response.WriteFile ("MyPart.html") %>
So my question is: what is the better way to do it? should I write a UserControl for each one of my parts, or should I user Resonse.WriteFile (...) for my non-server-side logic parts?

Upvotes: 1

Views: 242

Answers (2)

immutabl
immutabl

Reputation: 6903

I would tend to get away from using Response.WriteFile and in your case you should probably go with a combination of Master Pages and UserControls. The Master page will define the structure of all your site pages and such things as CSS and JavaScript files.

Within the Master Pages you can, esp. if your parts are dynamic e.g. a navigation menu that changes depending on where you are in the site) write these as UserControls and include them in your Master page markup definition.

Here's a simplified version of what I mean:

<html>
    <head>
        <link ... />
        <script type='text/jscript' href='/myjs.js' ></script>
    </head>
    <body>
        <uc1:TopMenu id='topMenu' .. /><!-- A usercontrol that generates the top menu -->
        <asp:ContentPlaceHolder id='cphBody'>

        <asp:/ContentPlaceholder/>
    </body>
</html>

Upvotes: 0

Albireo
Albireo

Reputation: 11095

Give a look to master pages, they allow you to apply templates to your site.

Upvotes: 1

Related Questions