(vbscript) GetRef and Response.Write

N

news

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 :)
 
N

news

<%
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...
 

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

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top