4

I searched a way to include a file in a web application (like a menu, so I won't have to edit it on all pages when applying changes), but haven't found something as simple as

<?php include "Menu.html"; ?>

Can you please help?

1
  • 2
    Fisrt: It's not PHP. Second: Learn about MasterPages, I bet you would love them. Commented Apr 17, 2012 at 13:09

6 Answers 6

5

Have you looked into Master Pages? They would certainly help you add the same layout across several pages.

Or perhaps you want a reusable User Control (that you write yourself)?

Sign up to request clarification or add additional context in comments.

Comments

4

We don't use "include page" in asp.net, even though it is possible (with a different syntax of course). Instead, have a look at Master page concept.

Comments

4

MasterPages allow you to maintain a parent/child relationship between a master page which contains content that wraps around any number of child content pages.

Similarly, UserControls allow you to re-use whatever content you want on whatever page you want, whether it's a MasterPage or ContentPage:

<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc" TagName="Spinner" 
    Src="~/Controls/Spinner.ascx" %>
<html>
<body>
<form runat="server">
    <uc:Spinner id="Spinner1" 
        runat="server" 
        MinValue="1" 
        MaxValue="10" />
</form>
</body>

8 Comments

Nope, you're wrong. Asp.net uses master pages. User controls serve different purpose.
I'm wrong in how I worded it, I'll rephrase, but I am right in that you can include whatever content you want in whatever page you want by using UserControls.
Yes, that is true, but it isn't an alternative to php's concept of building of main web template using includes. He explicitly stated he want to create one page which will act as a template, so that he won't need to write menu etc. on every page. That yells "master page!" :) Even though user controls can be used this way, I wouldn't advise to replace masterpages with them.
There are many scenarios out there and it's up to the developer to figure out which they need. They both serve a purpose and can be used similarly. I use them both in tandem in many projects.
And just to be clear he never stated he wanted to create one page which will act as a template. He said I searched a way to include a file in a web application (like a menu, so I won't have to edit it on all pages when applying changes), but haven't find something as simple as <?php include "Menu.html"; ?>. So, he was using the php as an example. He could be looking for either UserControls or MasterPages. Up to him to decide based on what exactly he's doing. =D
|
4

Methods (C#)

Executable code:

Page include

<!--#include file="a.aspx"-->

Execute independently inside a page

<% Server.Execute("a.aspx"); %>

Non-executable code:

<% Response.WriteFile("a.inc"); %>

Comments

2

I believe this is what you are looking for.

<!--#include file="wisdom.aspx"-->

Comments

2

I use C#.net

    <% Response.WriteFile("YourPage.aspx"); %>

and this works real well for me!!

I also use your line,

    <!--#include file="wisdom.aspx"-->

when I am in HTML mode.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.