Best way to create output

L

Luis

Which of the following two methods is the better method for creating a
table after doing some server side processing:

<%
if someCondition then
'do some server side stuff
Response.Write("<table><tr><td>table
content</td></tr></table>")
'do some more server side stuff
end if
%>

or

<%
if someCondition then
'do some server side stuff
%>
<table>
<tr>
<td>table content</td>
</tr>
</table>
<%
'do some more server side stuff
end if
%>

Does one have an adantage/disadvantage over the other?
 
B

Bullschmidt

They both perform about the same but for developer sanity reasons I
prefer the second method. Using one or the other is more a matter of
style (preference) than substance.

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 
S

swp

Which of the following two methods is the better method for creating a
table after doing some server side processing:

<%
if someCondition then
'do some server side stuff
Response.Write("<table><tr><td>table
content</td></tr></table>")
'do some more server side stuff
end if
%>

or

<%
if someCondition then
'do some server side stuff
%>
<table>
<tr>
<td>table content</td>
</tr>
</table>
<%
'do some more server side stuff
end if
%>

Does one have an adantage/disadvantage over the other?

The first method is generally slower, but offers the advantage of
allowing you to create re-usable code by putting the whole thing into
a procedure or function that can be called on demand from elsewhere.

Also, you do not indicate that any of the content of the table is
dependant upon what is done server-side. Is that intentional or an
oversight?

swp
 
J

Jeff Cochran

Which of the following two methods is the better method for creating a
table after doing some server side processing:

All you're asking is whether Response.Write of the HTML code is better
than just writing the HTML code outside the script portion of the
page. The answer is a definitive "Who cares?"

This is a programmer decision, has no effect on the output or
performance and the best method really depends on the content and how
you're putting it together. For example, if you're iterating through
a record set, doing the table in the script may make sense for
readability since a single line could write the row and the code can
loop trough that line for each item in the record set. But it really
makes no difference for anything other than the programmer.

Of course, if you program in a group, do it the way the group
mandates...

Jeff
 
R

Rob Meade

...
Which of the following two methods is the better method for creating a
table after doing some server side processing:

It would be much harder in your first example to indent all of the HTML into
a really nice (and yet slightly anal) fashion...something I believe all web
developers should do :eek:)

Regards

Rob
 
L

Luis

The first method is generally slower,

Slower performance?
but offers the advantage of
allowing you to create re-usable code by putting the whole thing into
a procedure or function that can be called on demand from elsewhere.

Also, you do not indicate that any of the content of the table is
dependant upon what is done server-side.

Generally it is - eg pulling info from a database and displaying it on
screen or building a list from data that's pulled off a database.

eg.

Response.Write("<table>")
....
do while not rs.eof
Response.Write("<tr><td>" & something & "</td></tr>")
rs.movenext
loop
....
Response.Write("</table>")

I could also write this as:

<table>
<%
....
do while not rs.eof
Response.Write("<tr><td>" & something & "</td></tr>")
rs.movenext
loop
....
%>
</table>

Is it better to Response.Write the <table> tags in this e.g.?
 
L

Luis

...

It would be much harder in your first example to indent all of the HTML into
a really nice (and yet slightly anal) fashion...something I believe all web
developers should do :eek:)
That's one of the reasons why I asked! I'm a sucker for neat code...
 
C

Chris Hohmann

swp said:
(e-mail address removed) (Luis) wrote in message

The first method is generally slower, but offers the advantage of
allowing you to create re-usable code by putting the whole thing into
a procedure or function that can be called on demand from elsewhere.

Both methods can be placed in a function/sub.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top