Response.Write vs <%= %>

后端 未结 15 2550
我在风中等你
我在风中等你 2020-12-28 14:34

Bearing in mind this is for classic asp

Which is better, all HTML contained within Response.Write Statements or inserting variables into HTML via &l

相关标签:
15条回答
  • 2020-12-28 15:03

    <%=Bazify()%> is useful when you are generating HTML from a short expression inline with some HTML.

    Response.Write "foo" is better when you need to do some HTML inline with a lot of code.

    Technically, they are the same.

    Speaking about your example, though, the Response.Write code does a lot of string concatenation with &, which is very slow in VBScript. Also, like Russell Myers said, it's not tabbed the same way as your other code, which might be unintentional.

    0 讨论(0)
  • 2020-12-28 15:06

    You should frame this questions in terms of code reuse and code maintainability (aka readability). There is really no performance gain either way.

    0 讨论(0)
  • 2020-12-28 15:08

    I agree with Jason, more so now that .NET is offering an MVC framework as an alternative to that awful Web Form/Postback/ViewState .NET started out with.

    Maybe it's because I was old-school classic ASP/HTML/JavaScript and not a VB desktop application programmer that caused me to just not grokk "The Way of the Web Form?" but I'm so pleased we seem to be going full circle and back to a methodology like Jason refers to.

    With that in mind, I'd always choose an included page containing your model/logic and <%= %> tokens within your, effectively template HTML "view." Your HTML will be more "readable" and your logic separated as much as classic ASP allows; you're killing a couple of birds with that stone.

    0 讨论(0)
提交回复
热议问题