Reputation: 525
i want to include other aspx file to main aspx file in asp.net i could do it in jsp the code in jsp include like that
<jsp:include page="footer.jsp" />
Upvotes: 13
Views: 43595
Reputation: 19
Using #include will not work because it will introduce two page directives if the included file is an ASP.NET page. The OP will have to use Ajax to download the file and then place it in the page.
Upvotes: 0
Reputation: 4891
This works for me. I can include my menu on any page I want:
<div ID="menuContent" runat="server">
<!-- #Include virtual="/menu.aspx" -->
</div>
In my menu.aspx file I have raw html and some C# codeblocks and ASP will resolve those after inserting the content into the page. Great huh?
Upvotes: 24
Reputation: 17614
You can not add another page to the existing page in asp.net.
Because asp.net
does not allow two form tag
in the same page.
There are feature like user control which you can use
More detail
http://www.codeproject.com/Articles/1739/User-controls-in-ASP-NET
Further more
There is a concept of Master page
and content page
Here is a good link for master page
http://www.codeproject.com/Articles/325865/Creating-Master-Page-In-ASP-NET-2010
Master page has a structure like below
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Few point to be noted
When you crate a Page you can add content only in ContentPlaceHolder1
, there can be many of these.
You can put your user-control
inside master-page
also so that it will be reflected all over you pages.
are actually user controls; you can verify this by going to the code-behind of your master page class, right-click on the class name and select "Go To Definition". You will see something like this:
public class MasterPage : UserControl
{
...
}
are convenient for display components that are repeated withing a single project, such as menus and panels. The problem is that they do not generate .DLLs and have to be hand-copied to other projects, if needed.
Some good links
ASP.NET equivalent of server side includes
How to include an external html file in asp.net page
Upvotes: 5
Reputation: 7872
ASP.Net have Master Page and User Control which help you do similar thing.
If you are using ASP.Net MVC, we have Partial View concept.
Upvotes: 1