Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   (vbscript) GetRef and Response.Write (http://www.velocityreviews.com/forums/t800002-vbscript-getref-and-response-write.html)

news@chthonic.f9.co.uk 11-11-2005 04:46 PM

(vbscript) GetRef and Response.Write
 
I'm trying to encapsulate a bunch of html widgets such that a
containing page can call them to draw themselves in whatever order it
chooses as well as easily add new ones.

In order to do this each widget registers itself by returning an id
code and a reference to the subroutine that generates its HTML content.

This works fine using vbScript's GetRef, but I've just noticed that if
the subroutine you get a reference to contains any Response.Write
statements, they get executed immediately as you take the reference and
not when the function is called. For example:

<%
dim functionReference

function renderWidget
response.write "bar"
renderWidget = "foo"
end function

functionReference = getRef("renderWidget")

response.write "---"
response.write functionReference
%>

You'd expect this to generate "---barfoo", but no, you get "bar---foo".

Clearly I'm hitting a response.write optimisation too far here and it's
easy to avoid, but thought people would be interested here :)


news@chthonic.f9.co.uk 11-11-2005 05:19 PM

Re: (vbscript) GetRef and Response.Write
 

news@chthonic.f9.co.uk wrote:

> <%
> dim functionReference
>
> function renderWidget
> response.write "bar"
> renderWidget = "foo"
> end function
>
> functionReference = getRef("renderWidget")
>
> response.write "---"
> response.write functionReference
> %>
>


Doing some more digging, it's not the response.write that is the
problem, it's the assignment of the result of GetRef.

If you do functionReference = GetRef("foo") then foo is executed there
and then and the result stored in the functionReference

if you do set functionReference = GetRef("foo") then it works as you'd
expect...



All times are GMT. The time now is 09:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.