Response.Write vs <%= %>

后端 未结 15 2700
我在风中等你
我在风中等你 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 14:53

    I prefer <%= %> solely because it makes Javascript development easier. You can write code that references your controls like this

    var myControl = document.getElementById('<%= myControl.ClientID %>');
    

    I can then use that control any way I'd like in my javascript code without having to worry about the hard coded IDs.

    Response.Write can break some ASP.NET AJAX code on some occasions so I try to avoid it unless using it for rendering specific things in custom controls.

提交回复
热议问题