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 ...
Get ASP.NET for Web Designers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.