tags:

views:

732

answers:

5

Is it possible to split large ASP.NET-pages into pieces? JSP has the jsp:include directive. Is there any equivivalent in ASP.NET

I'm not interested in reusing the pieces. I just want to organize the HTML/ASP code.

Isn't User Controls and Master Pages overkill for doing this?

+7  A: 

The MasterPage model and UserControls are the two out-of-box solutions to this.

John Rudy
+2  A: 

If it's only ASP.net, then User Controls are an excellent way of splitting up pages and reusing code, as John Rudy suggests.

If any of your user controls use Javascript, one big gotcha to watch out for is to use the ClientID to refer to that control. When you add a user control to a page, ASP.NET mangles the ID to prevent collisions. The client ID is guaranteed unique.

Ryan
Very good point!
John Rudy
A: 

You should take a look at ASP.NET User Controls which allow you to encapsulate UI functionality into smaller more manageable chunks.

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/userctrl/default.aspx

Kev
A: 

If you are talking about specific pages (as opposed to User Controls which are more intended for multi-page reuse than anything else), you could also use Partial Classes.

AFAIK in ASP.NET 2.0 and above ASPX pages are already Partial Classes by default (with all control declaration in the designer.aspx file).

Jon Limjap
Yes but I don't see how I'm able to split the .aspx-page using a partial class. I guess that the aspx.cs-file can be split by using partial classes but I want to split the HTML/ASP-code.
Ove
+1  A: 
<!--#include file="inc_footer.aspx"-->
liggett78
Beware of the caveats of #include in ASP.NET web forms. Some post back events don't respond to it very well.
Jon Limjap