C# ASP.NET design question

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Hi

I'm trying to understand avoiding duplicating html within a website. At the
same time
I'm trying to figure out how, when implementing page rendering functions,
how do I
use templates to keep html and code separate.

I define a class public class Page that extends/inherits from
System.Web.UI.Page. and
add various properties for getting/setting:
title
css files to include
menu item to highlight

And various methods for rendering elements of the page

I then override UI.Page's Render method in order to call
renderHeader
renderBody
renderFooter

How do I include a snippet of html in for example the renderHeader method()
also is there a specific
way i can use templates to set variable values in the page, without mixing
html with C# code?

Many Thanks for any help
Chris
 
A couple different things you could do:

1) Try user control (ascx) files. You can give them public properties
which you can set in the aspx or code-behind to modify the html they
spit out.

2) For things like headers and css files, use literal or placeholder
controls. Example: http://odetocode.com/Code/82.aspx. You could push
this code into a base class for all of your web forms to use.

These approaches would be more in-line with how ASP.NET apps are
traditionally built. Overriding render could leave piles of HTML
string literals inside of code.

My $0.02 :)
 
Back
Top