ASP.NET inline expressions

  • 3313
  • 0

ASP.NET inline expressions

<html>
<body>
    <form id="form1" runat="server">
    <% For i As Integer = 16 To 24 Step 2%>
    <div style="font-size: <% Response.Write(i)%>">
        Hello World<br />
    </div>
    <% Next%>
    </form>
</body>
</html>
  •   
<html>
<body>
    <form id="form1" runat="server">
    <%=DateTime.Now.ToString() %>
    </form>
</body>
</html>
  •   

@ Page

Defines page-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .aspx files.

@ Control

Defines control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files (user controls).

@ Import

Explicitly imports a namespace into a page or user control.

@ Implements

Declaratively indicates that a page or user control implements a specified .NET Framework interface.

@ Register

Associates aliases with namespaces and class names, thereby allowing user controls and custom server controls to be rendered when included in a requested page or user control.

@ Assembly

Links an assembly to the current page during compilation, making all the assembly's classes and interfaces available for use on the page.

@ Master

Identifies an ASP.NET master page.

@ WebHandler

Identifies an ASP.NET IHttpHandler page.

@ PreviousPageType

Provides the means to get strong typing against the previous page as accessed through the PreviousPage property.

@ MasterType

Assigns a class name to the Master property of an ASP.NET page, so that the page can get strongly typed references to members of the master page.

@ OutputCache

Declaratively controls the output caching policies of a page or user control.

@ Reference

Declaratively links a page or user control to the current page or user control.

  •   
<script runat="server">
    Protected Function SayHello() As String
        Return "Hello World"
    End Function

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
        lblHello.DataBind()
    End Sub
</script>
<html>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="lblHello" runat="server" Text="<%# SayHello%>"></asp:Label>
    </form>
</body>
</html>

 

<appSettings>
    <add key="copyright" value="(c) Copyright 2009 WebSiteName.com"/>
</appSettings>

The expression builder in the ASP.NET Web Form page:
<div id="footer">
    <asp:Literal ID="Literal1" runat="server" Text="<%$ AppSettings: copyright %>"></asp:Literal>
</div>
<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim strName As String
        strName = Session("userName")
        lblUserName.Text = strName
    End Sub
</script>
<html>
<body>
    <form id="form1" runat="server">
    <%-- Label for UserName --%>
    <asp:Label ID="lblUserName" runat="server" Text=""></asp:Label>
    </form>
</body>
</html>

參考自:http://www.kbalertz.com/976112/Introduction-inline-expressions-Framework.aspx

 

 

Hi, 

亂馬客Blog已移到了 「亂馬客​ : Re:從零開始的軟體開發生活

請大家繼續支持 ^_^