< %= % > and < % if Expression % > Syntax

The Web Control framework supports embedding FoxPro expressions into pages. This mechanism actually substitutes special controls into the page that handle expression evaluation.

Web Connection only supports two kinds of special embedded script tag formats:

IMPORTANT NOTE: Expression String Delimiters
HTML requires that expressions get embedded into the page with quotes and Web Connection will use double quotes for any embedded expressions it generates. This means your expression syntax should not use double quotes (") as string delimiter and instead use either square brackets([ ]) or single quotes (' ').

For example don't use: <% if(Tquery.Status = "Completed" %> but use <% if TQuery.Status = [Completed] %>.

<%= Expression %> Evaluation

The <%= %> syntax is the most efficient way to embed a dynamic value into the script page. This syntax actually maps to a wwWebEvalControl which handles displaying the expression and if there's an error displaying the error.

Typical examples:

<%= this.Page.oBusiness.oData.Title %> <%= this.Page.SomeStringReturningMethod() %> <%= TCursor.SomeField %>

These expressions can be embedded into page in place of any literal content. You can also use them inside of template controls like the wwWebRepeater Item Template for example.

Note that you cannot use <%= %> expressions inside of quoted attributes of controls, so the following does not work:

<ww:wwWebTextBox runat="server" id="txtName" Text="<%= TCursor.Name %>" />

Assignment to controls at runtime can be made either directly via code (this.txtName.Text = TCursor.Name from OnLoad or other event code) or by databinding via ControlSource:

<ww:wwWebTextBox runat="server" id="txtName" ControlSource="TCursor.Name" %> />

and you can then call either the Page's DataBind() method or the control's DataBind() (this.txtName.DataBind() ) method via code.

<% if Expression %> <% endif %>

Full FoxPro script processing like Script Templates is not supported in the Web Control Framework, so the <% %> script syntax is not supported. This is a design decision to discourage the use of embedding excessive code into pages, which should no longer be necessary with the new powerful control and code behind architecture.

However, there's one common usage pattern that is supported: Conditional display of content by using a conditional <% if %> block. The need to conditionally display a block of content is so frequent that an exception is built into the Web Connection framework to simplify displaying conditional content more easily using the <% if Expression %> <% endif %> syntax. Here's a short example:

Some text in my script page here

<% if this.Page.oBusiness.oData.LastAccess > Date() - 5 %>
Common content: <ww:wwWebLabel runat="server" ControlSource="this.Page.oBusiness.oData.Content" />
<hr>
<% endif %>

Some more text and controls here

The Web Control framework actually turns the conditional <% if %> expression into a wwWebPanel control with an invisible border. If the expression is false, the control is not rendered. The above actually is turned into:

<ww:wwWebPanel runat="server" VisibleExpression="this.Page.oBusiness.oData.LastAccess">
Common content: <ww:wwWebLabel runat="server" ControlSource="this.Page.oBusiness.oData.Content" />
<hr>
</ww:wwWebPanel>

Note that you can also use the wwWebPanel directly if you choose.

Also note that <% else %> is not supported. If you need an else condition you will need to explicitly define another < % if %> block with the negated expression in it. For example:

<% if this.Page.oBusiness.oData.LastAccess > Date() - 5 %>
Common content: <ww:wwWebLabel runat="server" ControlSource="this.Page.oBusiness.oData.Content" />
<hr>
<% endif %>
<% !if this.Page.oBusiness.oData.LastAccess > Date() - 5 %>
Display something else...
<hr>
<% endif %>



  Last Updated: 2/11/2007 | © West Wind Technologies, 2008