tags:

views:

122

answers:

3

Hi, Is there a c# command to include another web page - the equivelant of the php require? I know how to do server side includes but was looking for something code based. Thanks


Thanks for the answers all. I think I might need to explain further. I have several sub-pages that I will be loading during the use of the site using an xmlhttp request. Initially however, I need to load the starting sub-page before the user has interacted with the site. I could do this with js, but that would require more overhead in server calls from the client for the initial load. I already use master pages, but this is a little different. Since this is done serverside initally but must remain able to be refreshed clientside, I don't think I can make these pages into controls can I? I am pretty new to .Net so I may be making my life harder than I need to.

+5  A: 

I think what you may be looking for are MasterPages and UserControls. A MasterPage allows you to define a basic template that is "filled in" by the implementing pages by having the implementing page add it's own content to the ContentPlaceHolders defined on the MasterPage. A UserControl is a re-usable piece of markup and associated code that you can reference from your mark up or add dynamically to the page being rendered in codebehind.

tvanfosson
+1  A: 

The way ASP.NET is structured, you shouldn't really need to do this. Code is compiled, so all of your classes and functions should be accessible simply by referencing the relevant assembly or namespace, without having to include individual code files.

You might be looking for user controls, which allow you to create fragments of markup with their corresponding code behind, and then reference these in your page.

Mun
It sounds like I am overlooking something obvious. Can you explain just a little further or point me in the direction of something that explains in more depth?Thanks
Praesagus
Mun's answer is the best albeit a bit sparse on details. He pointed me in the right direction so I'll fill in the rest for any others with a similar question. Here is an example: Add <%@ Register TagPrefix="uc1" TagName="SampleUserControl" Src="SampleUserControl.ascx" %> to your parent page then <uc1:SampleUserControl id="SampleUserControl1" runat="server"></uc1:SampleUserControl> in the place you want to include it. Found on http://www.codersource.net/asp_net_web_user_controls.html
Praesagus
The disadvantage of using a control is that you cannot load it using xmlhttp later when you want to update your page on the fly.
Praesagus
+1  A: 

With ASP.NET MVC it looks like this:

<% Html.RenderPartial("LogOnUserControl"); %>

This way you can put another UserControl on your page.

Koistya Navin