Last post Apr 09, 2009 09:52 AM by Sabeltann
Apr 09, 2009 08:46 AM|Sabeltann|LINK
I’m trying to write a section of a page that is simple, read only and data driven html. I wondered if a custom server control was the appropriate tool, or what should I be doing
As a hobby and learning project, I’m trying to make a game review website (asp.net 3.5). There are a couple of principles I’d like to apply
Try to keep a clear distinction between the presentation layer and the data.
Minimize the amount of html bloat caused by unnecessary asp server tags, viewstate etc.
Styling to be achieved with css only (no hardcoded inline styles, no themes)
It’d be a bonus if the rendered html source was well indented and looked nice
A commonly used class will be a CReview with the following properties:
ID, category, headline, ingress, bodytext, list<string> imageurls
The review itself is basically readonly and pulled from the database by id (there will be nothing to trigger a postback here). The review page might have another section where visitors
can leave comments.
My server control would have properties for the CReview object, and various strings for styling of sections. So, on my page load event I’d get a CReview object by id, and set the
CReview property of my server control with this object. The server control would then render the review to html.
In my mind, the pagebody for a review might be as follows:
<!-- The readonly review section (made by my severcontrol?)-->
<h1>Headline goes here</h1>
Review text starts here...
And goes on and on...
<!-- The interactive comments section (a usercontrol made from standard asp servercontrols)-->
Apr 09, 2009 09:17 AM|mbanavige|LINK
i regularly use custom server controls and think they are often a good choice.
sometimes my controls are composites that use other server controls and other times, i just output some basic html more directly.
Apr 09, 2009 09:52 AM|Sabeltann|LINK
Thanks, for the reply - I had been thinking of making my control a composite of a custom 'text article' control and an 'image set' control. But then I started wondering if there was an easier way and I was just making things more complicated than necessary.
Do you think that it's an ok design to pass all of my content into the control in a CReview object? It'll mean that my custom control is only usable with this CReview object, but these reviews will be a pretty key feature of my site.