O'Reilly logo

ASP.NET for Web Designers by Peter Ladka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the LoadControl Method

One more very cool feature of User controls (and a major yucky of SSIs) is that they can be dynamically loaded with logic. This isn’t to say that you can’t dynamically execute the code in SSIs. This you can do as follows:

<%if var = 1 then%> 
<!--#include file="file1.inc" --> 
<%else%> 
<!--#include file="file2.inc" --> 
<%end if%> 

If var is equal to 1, then the code that is in file1.inc executes; otherwise the code in file2.inc executes. The thing to remember is that all the contents of both files will be included in the file, though. So if you have 10 include files with 200 lines of code each on your page, and only one of these will execute, you have a total of 2000 lines of code, 1800 of which aren’t needed and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required