(vbscript) GetRef and Response.Write

Discussion in 'ASP General' started by news@chthonic.f9.co.uk, Nov 11, 2005.

  1. 9.co.uk

    9.co.uk Guest

    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 :)
    9.co.uk, Nov 11, 2005
    #1
    1. Advertising

  2. 9.co.uk

    9.co.uk Guest

    9.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...
    9.co.uk, Nov 11, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    2
    Views:
    7,976
    Charles A. Lackman
    Jan 11, 2006
  2. Matthew Wieder

    Response.Write and Response.Redirect

    Matthew Wieder, Jul 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    678
    Kevin Spencer
    Jul 17, 2003
  3. Sehboo
    Replies:
    3
    Views:
    8,763
    Sehboo
    Dec 10, 2003
  4. slawekg

    Response.Write and Response.Redirect

    slawekg, Jun 21, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    367
    Alexey Smirnov
    Jun 21, 2007
  5. Mike Schinkel

    Bugs in VBScript GetRef()

    Mike Schinkel, Feb 29, 2004, in forum: ASP General
    Replies:
    6
    Views:
    253
    [MSFT]
    Mar 3, 2004
Loading...

Share This Page