views:

84

answers:

3

Hi there!

What is better coding practice, with speed in mind (Classic ASP):

sPg=sPg& "<select id=""actions"" onchange=""emact(this.value)"">"
sPg=sPg& "<option value=""""></option>"
sPg=sPg& "<option value=""read"">read</option>"
sPg=sPg& "<option value=""unread"">unread</option>"
sPg=sPg& "<option value=""spam"">spam</option>"
sPg=sPg& "<option value=""unspam"">unspam</option>"
sPg=sPg& "<option value=""delete"">delete</option>"
sPg=sPg& "<option value=""undelete"">undelete</option>"

OR

<select id="actions" onchange="emact(this.value)">
<option></option>
<option value="read">read</option>
<option value="unread">unread</option>
<option value="spam">spam</option>
<option value="unspam">unspam</option>
<option value="delete">delete</option>
<option value="undelete">undelete</option>

think this, but on a way larger scale (online store backend written this way almost completely, working on a new version) - I am going convert it all to easy to manage HTML instead of response.write each time, but I just want to know the by doing that, I am not digging myself a hole.

+1  A: 

If you are re-writing why are you going to use 10 year old technology?

(Use the 2nd one.)

Hogan
This is a fantastic point, however I'm not sure I have a choice...however before we begin I am rooting for a PHP conversion... we'll see.
Eddie
or .Net if they are already a MS shop. Classic ASP -> .NET is way easy (as microsoft intended) you can pick sections you want to upgrade (as I remember.)
Hogan
A: 

Wouldn't the argument for using Response.Write over HTML be the same one for parameterizing SQL statements over straight SQL queries? Meaning, to close a few loopholes for possible injection?

John at CashCommons
You still have to sanitize the user input -- it does not help AFAICT.
Hogan
(with parameterized sql the server enforces content and will not let the parameter end the current statement -- it also will also cache the execution plan in some cases).
Hogan
How does Response.Write close any injection loopholes? You still have to call any HTML-encoding function you want manually.
bobince
I guess it doesn't, then. Not having worked with it, I thought it might do some user input sanitation, but apparently not.
John at CashCommons
A: 

That's what I would do.

There is absolutely no good reason to go with creating the whole HTML structure through string concatenation, and you will gain a bit of performance by changing to straight HTML.

It would also be more maintainable, as you won't have to worry about escaping quotes and making sure your strings are properly concatenated.

Oded