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" 
    runat="server">
    <ItemTemplate>
        <%# Eval("MeetingName")%>
    </ItemTemplate>
</asp:Repeater>
 

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

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


Credits: http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-%283c25242c-3c253d2c-3c252c-3c252c-etc%29.aspx

Comments

Popular posts from this blog

Breaking down document locking in SharePoint

Working around X-Frame-Options for iframes

Document ID not being generated