Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Practice

Status
Not open for further replies.

jennuhw

MIS
Apr 18, 2001
426
US
I have been working with ASP and HTML now for about 6 months. I was wondering if it is better practice to do a response.write to enter html code or to end the ASP script to put the code in. I have been doing both depending on my mood at that moment.

Such as:

if not lors.eof then
response.write &quot;<font face=&quot;&quot;Tahoma&quot;&quot; size=&quot;&quot;3&quot;&quot;><B>Edit Time Cards<br><br></B>&quot;
response.write &quot;<select size=&quot;&quot;1&quot;&quot; name=&quot;&quot;associate1&quot;&quot; onchange=&quot;&quot;SubmitAuto()&quot;&quot; id=&quot;&quot;associate1&quot;&quot;>&quot;
response.write &quot;<option value=&quot;&quot;None&quot;&quot;>**Choose Employee**</option>&quot;

OR

if not lors.eof then %>
<font face=&quot;Tahoma&quot; size=&quot;3&quot;><B>Edit Time Cards<br><br></B>
<select size=&quot;1&quot; name=&quot;associate1&quot; onchange=&quot;SubmitAuto()&quot; id=&quot;associate1&quot;>
<option value=&quot;None&quot;>**Choose Employee**</option>

Just curious to see what the 'pros' do!! Thanks.
 
It's best to use response.write where you are using blocks of code. Everytime you close a tag and open a tag it's more work for the server to change to a different language engine.

 
I've actually had long discussions on this one. I believe that the performance tests have shown that the opening/closing of server-side delimiters had very little effect. Unless you're outputting over 1 million characters of HTML, the difference is VERY small (less than 1/2 a second).

So which should you do? Choose the method that makes you code most readable/understandable.

I've seen code with far too many delimiters and debugging was a chore. You might want to make a variable that you write once...

strHTML = &quot;<font face='Tahoma' size='3'><B>Edit Time Cards<br><br></B>&quot;&_
&quot;<select size='1' name='associate1' onchange='SubmitAuto()' id='associate1'>&quot;&_
&quot;<option value='None'>**Choose Employee**</option>&quot;

response.write strHTML

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks for the info. Right now, if I have to input some HTML and it is a bigger block, I will close the ASP script off. But it if just a short line, then I will do a response.write. So, I guess mixing it up is up to me!! Thanks a bunch!!



[ponytails]
 
just to add a late one. I completely agree with mwolf also. I've done some tests and seen otehrs here do the same. Although I've often been the first to say not to do it, the performance in doing it is not that hard of a hit. again, you can see a sec or two on a long winded script, but how often does a ASP script exceed the 2000 line mark.


_____________________________________________________________________
onpnt2.gif

 
just to add my two bob.
this article may be relevant although mostly concerned with ado and very large recordsets.

I have had to build a few dynamic reports with a Table Of Contents at the start. so i built the entire report out of various strings worked out the paging etc. these reports were round 50 pages printed.

They chugged a little cause i've heard that excessive string concatination can slow things a little
 
Excessive anything can slow something down, the question is what are you measuring against. Here's a link to a long post where I did concatenation vs multiple writes benchmarks. thread333-610504

In those tests I showed that 3 concatenations and one write are actually faster than 3 seperate writes. Later on when we got crazy I showed that some insanely large number of concatenations is worse than the equivalent number of writes. So yes at some point the number of concatenations will cause it to be slower than doing an equal number of writes, but we never actually found that number.

plus if you notice how many concat's i needed to make it a noticeable number you'll see how little conat's should affect your overall time compared to some other functions (such as manipulating recordset objects, which I benchmarked in a differant thread somewhere)

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
&quot;I was wondering if it is better practice to do a response.write to enter html code or to end the ASP script to put the code in.&quot;

My personal preference is generally to do the latter.

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top