home *** CD-ROM | disk | FTP | other *** search
Wrap
<%@Page Language="cs"%> <%@ Register TagPrefix="Acme" TagName="SourceRef" Src="/quickstart/util/SrcRef.aspx"%> <!-- #include virtual="/quickstart/aspplus/include/header.inc" --> <h4>Web Forms Syntax Reference</h4> <p> <div class="indent" style="font-family:Verdana; font-size:8pt;"> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#syntax">ASP+ Web Forms Syntax Elements</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#render">Rendering Code Syntax</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#code">Declaration Code Syntax</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#ctrl">ASP+ Server Control Syntax</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#htmlctrl">ASP+ Html Server Control Syntax </a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#databind">Databinding Syntax</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#object">Object Tag Syntax</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#comment">Server Side Comment Syntax</a><br> <b> <img align="middle" src="/quickstart/images/bullet.gif"> </b><a class="toc2" target="content" href="#include">Server Side Include Syntax</a><br> </div> <p> <hr> <!--BEGIN SECTION--> <a name="syntax"> <span class="subhead">ASP+ Web Forms Syntax Elements</span> <p> An ASP+ Web Form Page is a declarative text file with a ".ASPX" filename extension. In addition to static text content, it can contain eight distinct syntax markup elements. This section of the quickstart reviews each different syntax elements and provides an example demonstrating its use. <!--BEGIN SECTION--> <br> <a name="render"> <br> <span class="subhead">Rendering Code Syntax: <% %> and <%= %></span> <p> Code rendering blocks are denoted with <% ... %> elements, and enable developers to custom-control content emission. They execute during the "render" phase of page execution. The below sample demonstrates how they can be used to loop over some HTML content: <div class="code"><pre> <% for (int i=0; i<8; i++) { %> <font size="<%=i%>"> Hello World! </font> <br> <% } %> </pre></div> <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference1.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference1.src" Icon="/quickstart/aspplus/images/reference1.gif" Caption="Reference1.aspx" runat="server" /> <p> Code enclosed by <% ... %> is just executed, whereas expressions like <%= ... %> are evaluated and the result is emitted as content. Therefore <nobr><%="Hello World" %></nobr> is equivalent to <nobr><% Response.Write("Hello World"); %></nobr> (in C#). <p> <b>Note:</b> For languages, which utilize marks to end or separate statements (e.g. ";" in C#), it is important to respect them in both cases: <p> <div class="indent"> <table class="table2" cellpadding=3> <tr><th colspan="2"><b>C# code</b></th></tr> <tr> <td><div class="code"><% Response.Write("Hello World"); %></div></td> <td>semicolon is necessary to end statement</td></tr> <tr> <td><div class="code"><%="Hello World"; %></div></td> <td>WRONG: Would result in "<code>Response.Write("Hello World";);</code>"</td></tr> <tr> <td><div class="code"><%="Hello World" %></div></td><td>OK</td></tr> </table> </div> <!--BEGIN SECTION--> <br> <a name="code"> <br> <span class="subhead">Declaration Code Syntax: <script runat="server"> </span> <p> Code declaration blocks define member variables and methods that will be compiled into the generated Page class. Developers use these blocks to author page/navigation logic. The below example demonstrates how a "Subtract" method can be declared within a <script runat="server"> block, and then invoked from the page: <div class="code"><pre> <script language="C#" runat=server> int subtract(int num1, int num2) { return num1 - num2; } </script> <% ... number = subtract(number, 1); ... %> </pre></div> <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference2.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference2.src" Icon="/quickstart/aspplus/images/reference2.gif" Caption="Reference2.aspx" runat="server" /> <p> <b>Important:</b> Unlike ASP -- where functions could be declared within <% %> blocks -- all functions and global page variables must be declared in a <script runat=server> tag. Functions declared within <% %> block will now generate a syntax compile error. <!--BEGIN SECTION--> <br> <a name="ctrl"> <br> <span class="subhead">ASP+ Server Control Syntax</span> <p> Custom server controls enable page developers to dynamically generate HTML UI and respond to client requests. They are represented within a file using a declarative, tag-based syntax. These tags are distinguished from other tags because they contain a "runat=server" attribute. The below example demonstrates how a <asp:label runat="server"> server control can be used within an ASP+ Page. This control corresponds to the class Label in the <nobr>System.Web.UI.WebControls</nobr> namespace, which is included by default. <p> By adding a tag with the ID "Message", an instance of Label is created at runtime: <div class="code"><pre> <asp:label id="Message" font-size=24 runat="server"/> </pre></div> The control can then be accessed using the same name. The following line sets the Text property of the control: <div class="code"><pre> Message.Text = "Welcome to ASP+"; </pre></div> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference3.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference3.src" Icon="/quickstart/aspplus/images/reference3.gif" Caption="Reference3.aspx" runat="server" /> <!--BEGIN SECTION--> <br> <a name="htmlctrl"> <br> <span class="subhead">ASP+ Html Server Control Syntax </span> <p> HTML Server controls enable page developers to programmatically manipulate HTML elements within a page. An HTML server control tag is distinguished from client HTML elements by means of a "runat=server" attribute. The below example demonstrates how a HTML <span runat=server> server control can be used within an ASP+ Page. <p> As with other server controls, the methods and properties are accessible programmatically: <div class="code"><pre> <script language="C#" runat=server> void Page_Load(Object sender, EventArgs e) { Message.InnerHtml = "Welcome to ASP+"; } </script> ... <span id="Message" style="font-size:24" runat=server/> </pre></div> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference4.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference4.src" Icon="/quickstart/aspplus/images/reference4.gif" Caption="Reference4.aspx" runat="server" /> <!--BEGIN SECTION--> <br> <a name="databind"> <br> <span class="subhead">Databinding Syntax: <%# %> </span> <p> The DataBinding support built into ASP+ enables page developers to hierarchically bind control properties to data container values. Code located within a <%# %> code block is only executed when the "DataBind" method of its parent control container is invoked. The below sample demonstrates how to use the databinding syntax within a <asp:datalist runat=server> control. <p> Within the datalist the template for one item is specified. Container.DataItem refers to the data source of the datalist "MyList": <div class="code"><pre> <asp:datalist id="MyList" runat=server> <template name="ItemTemplate"> Here is a value: <%# Container.DataItem %> </template> </asp:datalist> </pre></div> In this case the datasource of the "MyList" control is set programmatically, then DataBind() is called: <div class="code"><xmp> void Page_Load(Object sender, EventArgs e) { ArrayList items = new ArrayList(); items.Add("One"); items.Add("Two"); items.Add("Three"); MyList.DataSource = items; MyList.DataBind(); } </xmp></div> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference5.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference5.src" Icon="/quickstart/aspplus/images/reference5.gif" Caption="Reference5.aspx" runat="server" /> <!--BEGIN SECTION--> <br> <a name="object"> <br> <span class="subhead">Object Tag Syntax: <object runat="server" /></span> <p> Object Tags enable page developers to declare and instantiate variables using a declarative, tag-based, syntax. The below sample demonstrates how the object tag can be used to instantiate an arraylist class instance: <div class="code"><pre> <object id="items" class="System.Collections.ArrayList" runat="server"/> </pre></div> The object will be created autmically at runtime and can then be accessed via the the ID "item": <div class="code"><pre> void Page_Load(Object sender, EventArgs e) { items.Add("One"); items.Add("Two"); items.Add("Three"); ... } </div></pre> <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference6.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference6.src" Icon="/quickstart/aspplus/images/reference6.gif" Caption="Reference6.aspx" runat="server" /> <!--BEGIN SECTION--> <br> <a name="comment"> <br> <span class="subhead">Server Side Comment Syntax: <%-- Comment --%></span> <p> Server-Side Comments enable page developers to prevent server code (including server controls) and static content from executing/rendering. The below sample demonstrates how to block content from executing and/or being sent down to a client. Note, that everything between <%-- and --%> is filtered out and only visible in the original server file, even though it contains other ASP+ directives: <div class="code"><pre> <%-- <asp:calendar id="MyCal" runat=server/> <% for (int i=0; i<45; i++) { %> Hello World <br> <% } %> --%> </pre></div> <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference7.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference7.src" Icon="/quickstart/aspplus/images/reference7.gif" Caption="Reference7.aspx" runat="server" /> <!--BEGIN SECTION--> <br> <a name="include"> <br> <span class="subhead">Server Side Include Syntax: <-- #Include File="Locaton.inc" --></span> <p> Server-Side #Includes enable developers to insert the raw contents of a specified file anywhere within an ASP+ Page. The below sample demonstrates how to insert a custom header and footer within a page: <div class="code"><pre> <!-- #Include File="Header.inc" --> ... <!-- #Include File="Footer.inc" --> </pre></div> <p> <Acme:SourceRef RunSample="/quickstart/aspplus/samples/webforms/reference/reference8.aspx" ViewSource="/quickstart/aspplus/samples/webforms/reference/reference8.src" Icon="/quickstart/aspplus/images/reference8.gif" Caption="Reference8.aspx" runat="server" /> <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->