Subject: Server Includes - ASP.Net equivalent
Posted By: rit01 Post Date: 2/20/2006 5:27:31 AM
Hi All

I have a snippet of code that needs to be included in each Page_Load event. I am from an ASP background and used to achieve this through using includes. When adding an include (<!-- #include -->) within the <script> tags it doesn't like it. I get:

Server includes are not allowed in server script tags

What would the nice and shiny asp.net2 equivalent be?

Ta

Rit
Reply By: Imar Reply Date: 2/20/2006 12:00:32 PM
Hi Rit,

Although you can still use include files to include static content somewhere in the page, it's not recommended to do so. As you found out, you can also no longer include files within script tags (you never could, BTW)

In .NET, there are much better and efficient means to reuse content and functionality.

If you want to share presentation, you can use User Controls (files ending with an .ascx extension). These controls, little ASPX pages, can hold controls, markup etc and can have Code Behind files like .aspx pages do.

If you want to reuse functionality (e.g. functions doing things, or returning stuff), in ASP.NET 2 you have a couple of options.

First of all, you can create a class file in the App_Code folder that contains shared or instance methods. From your ASPX pages, you can access these classes and methods.

Alternatively, you can create a Class Library project. At first sight, this looks like classes in the App_Code folder (in terms of how you can access the code), but it allows you to create an assembly that can be reused across multiple applications.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply By: rit01 Reply Date: 2/21/2006 9:31:35 AM
Always helpful. Many thanks Imar.

Rit

Go to topic 40372

Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360
Return to index page 359
Return to index page 358
Return to index page 357
Return to index page 356
Return to index page 355
Return to index page 354