http://www.aspcn.com 飞刀
前面我们看到了对于移动控件的介绍,现在我们具体来看看他的用法.
使用移动控制
使用移动控制就和使用其它ASP+控制一样简单。事实上他更加简单,因为他是产生整个页面,而不是部分页面。我们甚至
不必去考虑
和
1<doctype .......="">这些标签,他们会自动添加。
2
3我们使用Paner控制来产生<card>和<deck>
4<mobile:panel id="pnlMain" runat="server">
5<mobile:form runat="server">
6<mobile:label runat="server">Enter your name:</mobile:label>
7<mobile:textbox id="NameEdit" runat="server"></mobile:textbox>
8<mobile:command id="Button" label="OK" onclick="Button_OnClick" runat="server" targettype="FormAccept"></mobile:command>
9</mobile:form>
10</mobile:panel>
11
12注意:在以前的版本中,每个页面必须有一个Mobile:form,现在不需要了。
13
14下面是上面的程序在普通浏览器上看到的结果:
15
16
17
18但是,如果您用WAP手机来观看,就会看到下面的结果 :
19
20
21
22下面我们将在页面中加上一个包含用户名的欢迎信息,因此我们得在这个deck中加上另外一个Panel控制。
23
24<mobile:panel id="pnlTwo" runat="server">
25<mobile:form runat="server">
26<mobile:label id="WelcomeMessage" runat="server" type="Title"></mobile:label>
27</mobile:form>
28</mobile:panel>
29
30我们让用户按下OK键后再显示这个信息。在WAP手机中有不同的操作方法,意思一样。所以,我们还得写一此VB代码来处理
31这个事件。
32
33<script language="vb" runat="server">
34Sub Button_OnClick(Sender As Object, Args As EventArgs)
35WelcomeMessage.Text = "Welcome '" & NameEdit.Text & "'"
36SetCurrentPanel (pnlTwo)
37End Sub
38</script>
39
40在第一个card(或者是panel)中包含一个command控制,它指定了事件和铵钮的名字:
41
42<mobile:command id="Button" label="OK" onclick="Button_OnClick" runat="server" targettype="FormAccept"></mobile:command>
43
44子程序中的代码主要是用于从Textbox控制中收集用户名,然后在第二个panel中的labael显示:
45
46WelcomeMessage.Text = "Welcome '" & NameEdit.Text & "'"
47
48当这些都完成了,我们就来启动每个页面
49
50SetCurrentPanel (pnlTwo)</deck></card></doctype>