A common question asked by developers new to WML is how can they
pass values between WML client-side variables and ASP server-side
variables. The following example illustrates the case:
<% Response.ContentType = "text/vnd.wap.wml" %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Card 1">
<p>
x is 500 (in
ASP)
<% x = 500
%>
<do
type="accept" label="Card 2">
<go href="#card2" method="get">
<setvar name="x" value="<% =x %>" />
</go>
</do>
</p>
</card>
<card id="card2" title="Card 2">
<p>
The value of x
is $(x) (in WML)
</p>
</card>
</wml>


Here, I'm passing the value of x in ASP to the variable in x in
WML. I make use of a <setvar> element to pass the value from
ASP to WML.
Passing Values from WML to ASP
How about the other way round?
<% Response.ContentType = "text/vnd.wap.wml" %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Card 1">
<p>
How many stars
do you want to display?
<select
name="loop">
<option value="1">1 star</option>
<option value="2">2 stars</option>
<option value="3">3 stars</option>
<option value="4">4 stars</option>
</select>
<do
type="accept" label="Display">
<go href="#card2" method="get">
<postfield name="loop" value="$loop" />
</go>
</do>
</p>
</card>
<card id="card2" title="Card 2">
<p>
<% loopcount
= Request.QueryString("loop")
For i= 1 To loopcount
Response.Write "*"
Next
%>
</p>
</card>
</wml>


In this case, I'm using the <postfield> element to pass
the value to card2:
<postfield name="loop" value="$loop"/>
And in card2, I've used the Request.QueryString collection to
retrieve and assign the value to the variable loopcount in ASP:
<% loopcount
= Request.QueryString("loop")
Tips for Using ASP to Generate WML Content
When generating WML content using ASP, bear in mind that a deck
can contain multiple cards. If your content for each card is
generated dynamically, it may have an impact on the efficiency of
your web server. To illustrate this, consider the following
example:
<% Response.ContentType = "text/vnd.wap.wml" %>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<!-- First Card -->
<card id="card1" title="Card1">
<p>
Time on card 1
is : <% =time %>
<do
type="accept" label="Card2">
<go href="#card2" />
</do>
</p>
</card>
<!-- Second Card -->
<card id="card2" title="Card2">
<p>
Time on card 2
is : <% =time %>
<do
type="accept" label="Card1">
<go href="#card1" />
</do>
</p>
</card>
</wml>
When the ASP parser parses the above deck, both cards will be
'given' the same time. When the user moves from card1 to card2,
they will see the same time on both cards. This may not be what we
intended - we might want the cards to contain the different
times that they were displayed on the WAP device.
To solve this problem, I need to make sure that caching is
turned off on the WAP device. For this, I can use the
Response.Expires property, as described earlier in the paper.
However, this causes the deck to be parsed twice by the ASP
parser, as the WAP device will have to reload the same deck from
the origin server to display the second card.

Remember: caching is at deck level. When a user moves
from a card to another within a deck, using a Response.Expires
property will not cause a reload of the deck from the origin
server.
Hence, when you have dynamic content on multiple cards within a
deck, it is important that these cards be separated into different
decks. The diagram showing the request and response between the WAP
device and origin server is valid provided caching can be
done at the card level.
As can be seen, every time the WAP device requests the same
deck, the ASP server spends time parsing it. If the deck contained
a lot of cards, the time needed would be substantial: this is
inefficient. Instead, by breaking the cards down into multiple
decks, the time spent parsing individual decks is reduced.
Common Errors
Finally, let's briefly examine some of the common errors that
developers may encounter when using ASP to generate WML
content.
Not setting the correct MIME type
The WML MIME type must be set using the Response.ContentType
property, like this:
<% Response.ContentType = "text/vnd.wap.wml" %>
Cookies are not supported
When using cookies or the Session object, always ensure that the
target platform is capable of supporting cookies.
The POST method may not work correctly on some
WAP devices
When using a <postfield> element, be aware that some WAP
devices (the Nokia 7110, for instance) have problems in supporting
the POST method.
You need a web server to run ASP!
Very often, people just run ASP documents straight from their
local hard disk. ASP documents require a web server (in particular,
the ASP parser) to process them, so that the resulting page can be
sent to the client. Also important point to note is that you need
to use the http:// syntax, and not the physical
filename.