ASP PAGE STRUCTURE(CODE RENDER BLOCKS)

Code Render Blocks

  • If  we need to execute code within the HTML or text content of  ASP.NET page, we can do so within code render blocks. 
  • The two types of code render blocks are inline code and inline expressions.
  •  Inline code executes a statement or series of statements. 
  • This type of code begins with the characters <% and ends with the characters %>.
  • Inline expressions, on the other hand, display the value of a variable or method (this type of code is shorthand for Response.Write).
  •  Inline expressions begin with the characters <%= and end with the characters %>.


Example:
<Script Runat="Server">
 Dim strSomeText As String

 Sub Page_Load
  strSomeText = "Hello!"
 End Sub
</Script>

<html>
<head><title>CodeRender.aspx</title></head>
<body>

<form Runat="Server">

The value of strSomeText is:
<%=strSomeText%>

<p>

<% strSomeText = "Goodbye!" %>
The value of strSomeText is:
<%=strSomeText%>

</form>

</body>
</html>


  • We can use variables declared in the code declaration block within the code render block.
  •  However, the variable has to be declared with page scope.
  • The variable could not, for example, be declared within the Page_Load subroutine.


No comments:

Post a Comment