본문 바로가기
개발/ASP.NET

[C#] ASPX 파일 내에서 사용되는 C# 태그 구분

by ispie 2022. 12. 14.

작성 경위

<%: %> 태그는 자동으로 HtmlEncode를 해 준다는 것을 모르고 개행 태그를 가진 변수값을 표시하려다가 각 태그별 특성을 정리된 것이 있길래 가져와 보았습니다. (해당 문제는 <%= %>로 해결하였음)

ASPX 파일 내에서 사용되는 C# 태그의 차이점

1. <% %>

An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class.

2. <%= %>

most useful for displaying single pieces of information.

3. <%# %>

Data Binding Expression Syntax. http://msdn.microsoft.com/en-us/library/bda9bbfx.aspx

4. <%$ %>

ASP.NET Expression. http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx

5. <%@ %>

Directive Syntax. http://msdn.microsoft.com/en-us/library/xz702w3e(VS.80).aspx

6. <%-- --%>

Server-Side Comments. http://msdn.microsoft.com/en-US/library/4acf8afk.aspx

7. <%: %>

Like <%= %> But HtmlEncodes the output (new with Asp.Net 4). http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx

 

 

출처 : what are these special tags <%# and <%=

 

what are these special tags <%# and <%=

User-2041805088 posted <%# is a data binding syntax for use in databound controls. <%= is a short cut for Response.Write. <%@ is a directive to include a namespace, page directives, etc.

social.msdn.microsoft.com

 

2020-02-06 최초 작성

댓글