How to include another .NET page in your current page ?

Hello,

Very simple question how do you include another .NET page in another ?
Like say a include=test.aspx or something.
0
yaf23
5/7/2004 4:47:10 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 2 followers.

💬 5 Replies
👁️‍🗨️ 484 Views

I don't think it is possible and if it is, please someone show me some example code. What you can do is create user controls (*.ascx) and dynamically include  them.

On your page you can set a PlaceHolder control and in your code behind you could attach a user control to it

PlaceHolderControlOnPage.Controls.Add(LoadControl("test.ascx"))

Grz, Kris.
Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
5/7/2004 5:00:09 PM
Well, the #include directive can still be used, but as Jason Fly said, it's better to use User Controls. You do not have to dynamically load them, though, you can also @Register them and use them declaratively.
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
0
bleroy
5/7/2004 7:10:56 PM
Okay, but does this apply to html pages as well.  The primary reason I want to do this is that I have an aspx page that only contains the website banner with a bunch of different images in tables the full file is below.  Now if things change with the heading I don't want to have to put this code in all pages and then have to go to each to change the image or link.  I would just like to go to one central page to make changes.


Here is the full page:


<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td colspan="7">
<img height="129" src="images/banner.gif" width="695" /></td>
</tr>
<tr>
<td>
<img height="19" src="img1.gif1" width="137" /></td>
<td>
<img height="19" src="img1.gif2" width="50" /></td>
<td>
<img height="19" src="img1.gif3" width="124" /></td>
<td>
<img height="19" src="img1.gif4" width="106" /></td>
<td>
<img height="19" src="img1.gif5" width="104" /></td>
<td>
<img height="19" src="img1.gif6" width="136" /></td>
<td>
<img height="19" src="img1.gif7" width="38" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td valign="top">
<img height="61" src="img2.gif" width="137" /></td>
<td valign="top">





Content




</td>
</tr>
</tbody>
</table>
</body>
</html>

0
yaf23
5/7/2004 7:26:41 PM
Sure, this is exactly what User Controls are about.
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
0
bleroy
5/7/2004 8:03:23 PM
if the html your trying to "include" everywhere does not require any code behind, then i would recommend that you dont use a usercontrol

usercontrols require additional overhead as they go through essentially the same init/load etc.. cycle that a page goes through. when there's no need for codebehind, you're just wasting cpu cycles.
on our site we use a combination of user controls (when necessary) and "included" html.
the html fragments that i need to include are stored in a text file in a subfolder of the web.
at application startup, i load the text from these files into application variables
i.e.
application("Banner") = GetMyBannerFile()
application("Footer") = GetMyFooterFile()
on each of my pages is a placeholder that gets replaced with the appropriate content at runtime.
since the content actually comes from an app var (in memory), you get the added benefit of not having to hit the disk for the extra html on every page request. to change my banner, i edit the html fragment i stored in the text file and reload it into the app var.
voila - all pages in the site are using the new banner.

Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
5/7/2004 9:39:56 PM
Reply: