Monday, April 8, 2013

ASP.NET | Server side code blocks

Understanding code blocks is a great way of using all the power of ASPX pages.

Here's a list of existing tags and their usage.

<%   %>
Usage: most common code block. enables most C# coding such as conditions and others, placing rendering code outside

<% if (User.IsInRole("admin")) {  %>
You can see this 
<%  } else { %>  
You are not admin! 
<%} %>

<% if(true) Response.Write(Request.Url.ToString()); %>

<%#   %>
Usage: common for Eval() and Bind(), to show a data connection field (eval) or link one (bind)
<asp:Repeater ID="rptMeetings" DataSourceID="meetings" 
        <%# Eval("MeetingName")%>

<%=   %>
Usage: Output a single field directly into the current position within the aspx file. No end comma required.

<%= Request.Url.Host.ToString() %>


No comments:

Post a Comment