[thelist] Response.Write versus varHTML = varHTML & "..."

Warden, Matt mwarden at mattwarden.com
Fri Jan 11 15:22:36 CST 2002


On Jan 11, Anthony Baratta had something to say about Re: [thelist]..."

>At 09:39 AM 1/11/2002, Howard Cheng wrote:
>>I'll have to concur with Joshua Olson in that it's usually easier to do 
>>all your queries and server-side calculations before you output the HTML, 
>>storing any results of said calculations into variables and just printing 
>>those variables at the end. Or at least as much as possible at any rate. 
>>Certainly sometimes you need dynamic branching in your HTML, but you can 
>>always have the values ready ahead of time and do function calls with 
>>those values.
>
>This doesn't solve the problem with string concatenation/storage. Where do 
>you store the HTML text before you get to the HTML?

I don't understand what you mean. I'll try to just explain what I do and
hopefully that will answer your question.

My aproach that I've been using for 3+ years now is just about the
opposite of yours.

This is on the assumption that the page has multiple functions (add,
delete, modify, etc.)

I first declare subroutines. All output is in subroutines.


<%
sub head()
	' write common header
	' this sub is actually usually in an include
	response.write "<html>...<body>"
end sub

sub footer()
	'...
end sub


sub listproducts(byval iCategoryID)
	' dont bitch about my parenthesis, damn you!
	call head()
%>
	<table ...>
	<!-- initial formatting -->
<%
	sSQL = "select ID, Name from Product where categoryid="&iCategoryID
	' ... and so on
%>
	</table>
<%
	call footer()
end sub


sub editproductlist(byval iCategoryID)
	'...
end sub

%>

You get the idea. Then I stuff any non-output functionality where i need a
return value (such as a newly-added product id) into functions. I'll spare
you the example.

Then I have a short global declaration section, possibly with some simple
logic:

<%

g_iCategoryID = trim(Request("cid"))

if g_iCategoryID = "" then
	g_iCategoryID = 1
end if

%>

or something like that.

then, i have what i call the runtime section (who knows whether that's a
proper name) that's very similar to what you had.

<%
select case lcase(request("action"))
	case "add"
		g_iProductID = addNewProd()
		' again, leave my parens alone!  ;-)
		call ShowProductDetail(a_iProductID)
	case "del"
		g_iProductID = Request("pid")
		call DeleteProd(g_iProductID)
		call listproducts(g_iCategoryID)
	case "save"
		'...
	case else
		call listproducts(g_iCategoryID)
end select
%>

The nice thing about this is that it's very easy to control operations
based on privleges. All you have to do is wrap the restricted action
within the select case with and 'if conditional'.

Hopefully I answered your question. And if not, hopefully this is at least
somewhat helpful to someone.

Thanks,

--
mattwarden
mattwarden.com








More information about the thelist mailing list