tags:

views:

45

answers:

3

I know the question is a bit subjective, but often there is a consensus as to a whether a style should be avoided or is considered harmless.

I have elements of actual HTML mixed in with a lot of my ASP.NET markup. I don't know enough about what goes on in the background to determine whether this should be avoided or if it is harmless.

I recently read that all styling elements should be left out of ASPX files and relegated to CSS; this seems wise for a variety of reasons.

I'm wondering if HTML code should be replaced by corresponding ASP as it is harder to control from the code behind, or if it is perhaps recommended to put actual HTML code as it is less do to when the page is rendered.

+3  A: 

When the asp.net compiler parses your .aspx files, it converts everything that's not already a runat="server" control into an <asp:literal> control so that it can construct code (be it c# or vb.net) from your markup that generates the page.

Ultimately there's probably very little difference, performance wise, but if you have no reason to manipulate a particular element from your codebehind it probably makes sense to leave it as "pure" HTML, for readability if nothing else.

Rob
+2  A: 

I think it's nothing wrong to put HTML in ASPX page if this part is actually static, for example I often to use HTML tables in ASPX. Page will be rendering faster if you don't use server controls where it's not necessary.

Alex
@Alex, as the asp.net compiler transforms all non server-control markup into `<asp:literal>` s, render performance is pretty much the same whether you do it yourself (by turning `div`'s into `runat="server"`, for example) or let the compiler do it for you =)
Rob
ok, didn't know that, thanks.
Alex
+1  A: 

I like to keep my HTML just HTML so that it is clear to anyone else looking at my code in the future what elements are potentially referenced in server side logic without having to compare code behind files to .aspx pages to see what is used in server side code or not.

That way someone can easily tell from looking at the "design" of the page what elements are processed on the back end. Either way, like noted probably not a major performance difference, but more a good practice IMO.

jaywon