aspxtreme

Code Render Blocks

ASP.NET Syntax   ASP.NET Page Syntax


Defines inline code or inline expressions that execute when the page is rendered. There are two styles: inline code and inline expressions. Use inline code to define self-contained code blocks or control flow blocks.

<% inline code %>

Use inline expressions as a shortcut for calling the HttpResponse.Write method.

<%=inline expression %>

Remarks

A compilation error occurs if you try to include the character sequence %> anywhere inside a code render block. That sequence can only be used to close the code render block. For example, the following code fragment will cause an error:

<%@ page language="C#" %>
<% Response.Write ( " %>" ); %>
  C# VB

To work around this error, you can build a string containing the sequence of characters.

<%@ page language="C#" %>
<% String s = "%" + ">";
   Response.Write ( s ); %>
  C# VB

NOTE: Unlike Active Server Pages ( ASP ), it is illegal to declare a function or sub routine within a code render block ( between <% and %> tags ) in ASP.NET.

Syntax Example

The below code snippet shows how you can use the render blocks to display the same HTML text in a number of different font sizes.

<% for ( int i=0; i<10; i++ ) { %>
     <font size = "<% i %>"> Hello World! 
<% } %>
  C# VB

See Also

Introduction to Web Forms



Books and more ...


Suggested Reading

Need a break ?



Previous page Back to top Next page

Check out related books at Amazon

© 2000-2008 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support aspxtreme