
 
 | 
| 技术资料  > ASP技术 > 系统相关 : 让您的主页支持各种浏览设备(ASP+篇)(上) |  
让您的主页支持各种浏览设备(ASP+篇)(上) March 25,2004 |  
http://www.aspcn.com 飞刀 
前面我们看到了对于移动控件的介绍,现在我们具体来看看他的用法. 
 
使用移动控制 
使用移动控制就和使用其它ASP+控制一样简单。事实上他更加简单,因为他是产生整个页面,而不是部分页面。我们甚至 
不必去考虑<? xml ....?>和<doctype .......>这些标签,他们会自动添加。 
 
我们使用Paner控制来产生<card>和<deck> 
 
<Mobile:Panel runat="server" id="pnlMain"> 
  <Mobile:Form runat="server"> 
    <Mobile:Label runat="server">Enter your name:</Mobile:Label> 
    <Mobile:TextBox runat="server" id="NameEdit" /> 
    <Mobile:Command runat="server" id="Button" Label="OK" 
            TargetType="FormAccept" OnClick="Button_OnClick" /> 
  </Mobile:Form> 
</Mobile:Panel>  
 
注意:在以前的版本中,每个页面必须有一个Mobile:form,现在不需要了。 
 
下面是上面的程序在普通浏览器上看到的结果: 
 
 
 
但是,如果您用WAP手机来观看,就会看到下面的结果 : 
 
 
 
下面我们将在页面中加上一个包含用户名的欢迎信息,因此我们得在这个deck中加上另外一个Panel控制。 
 
<Mobile:Panel runat=server id="pnlTwo"> 
  <Mobile:Form runat="server"> 
    <Mobile:Label runat="server" id="WelcomeMessage" Type="Title"/> 
  </Mobile:Form> 
</Mobile:Panel> 
 
我们让用户按下OK键后再显示这个信息。在WAP手机中有不同的操作方法,意思一样。所以,我们还得写一此VB代码来处理 
这个事件。 
 
<script language="vb" runat="server"> 
  Sub Button_OnClick(Sender As Object, Args As EventArgs) 
    WelcomeMessage.Text = "Welcome '" & NameEdit.Text & "'" 
    SetCurrentPanel (pnlTwo) 
  End Sub 
</script> 
 
在第一个card(或者是panel)中包含一个command控制,它指定了事件和铵钮的名字: 
 
<Mobile:Command runat="server" id="Button" Label="OK" 
  TargetType="FormAccept" OnClick="Button_OnClick" /> 
 
子程序中的代码主要是用于从Textbox控制中收集用户名,然后在第二个panel中的labael显示: 
 
WelcomeMessage.Text = "Welcome '" & NameEdit.Text & "'" 
 
当这些都完成了,我们就来启动每个页面 
 
SetCurrentPanel (pnlTwo) 
 
         |  
 
 | 
  
Copyright © 2001-2008 Shenzhen Hiblue Software Team All rights reserved