views:

180

answers:

2

Working on an old site in asp classic. I want to write a function that returns some html. Right now I'm reduced to writing everything in a string.

The downsides are:

  • I have to escape quotes
  • There is no code completion on the tags nor attributes

In php I know how to get the contents of the output buffer with ob_get_contents. Is there an equivalent function in asp classic?

+2  A: 

There is no way to access the Response buffer contents in ASP.

When code generating a HTML content string gets ugly I tend to resort to using an MSXML dom document as a place to create the content. Then return the .XML property of the DOM, not effecient but when done properly much more readable.

Alternatively if you know that the only thing that will be done with the string once returned is to write it to the response then you can just do that directly in the function (or a Sub if you are using VBScript).

Its worth noting that you do this sort of thing in a Sub procedure in ASP:-

Sub WriteRow(first, second)
%>
    <tr>
      <td><%=Server.HTMLEncode(first)%></td>
      <td><%=Server.HTMLEncode(second)%></td>
    </tr>
<%
End Sub

Now you can call WriteRow in a loop. If you have a lot of boilerplate HTML with just a little dynamic content then this may be an option.

AnthonyWJones
A: 

Check this page, and this page

Filip Ekberg
... or save your time and read this short summary of these two pages: There's no functionality to emulate ob_get_contents() in classic ASP (as said by Anthony).
BlaM