I have had a php site for about 10 years now, and tweaked and tuned it over these years to finally knock it down to a page of common functions, and about 10 content pages.
However, I want to learn .NET. I have touched on .NET at work in the past, but have never dealt with anything as… specific?… as my site there.
…OK, I am babbling, sorry. Bottom line is:
Can/should I be using a function in asp.net where in php I would have a function:
<? DrawMapTable("id", "MapName", "Description.", "Filename", "Players", "MapSize", "Game") ?>
Which would draw a table, such as:
<h3> <a> $mapNameFull </a> </h3><img class='mapImage' src='images/$mapName.png' alt='$mapNameFull' /><p>$mapDescription</p><p><a href='maps/$fileMapName'>Download map: $mapNameFull</a></p>
<table class='mapTable'><tr><th class='mapTableCellBig'> Map Name </th><th class='mapTableCell'> Players </th><th class='mapTableCell'> Dimensions </th><th class='mapTableCell'> Version </th></tr><tr>
<td class='mapTableCellBig'> <a href='maps/$fileMapName'>$fileMapName</a> </td><td class='mapTableCell'> $mapPlayers </td><td class='mapTableCell'> $mapDims </td><td class='mapTableCell'> $mapVersion </td></tr></table>
And if so, how?
ATTEMPT AT A BETTER EXPLANATION:
For example, if I have this in my master codebehind page:
public String SectionBreak()
{
string sHtml = "";
sHtml += " </td></tr>\n";
sHtml += " <tr><td class='mainCell'>\n";
return sHtml;
}
- How would I call it in, say, default.aspx
- Is this a horrible thing to do?
Basically, I am trying to get away from using html in my content pages by obscuring it within functions that explain what the html is doing.
But the only way I can think to do this at the moment is to create a load of labels and have an onLoad for each of those labels, which would populate it with the code from, for example, SectionBreak().
In classic ASP.NET you have server side controls which generate HTML fragments. For example when dealing with tables, you could use the GridView control.