top
Loading...
創建移動Web應用程序(5)
一個簡單的例子

讓我們寫一個簡單應用程序,顯示一個文本框接受輸入并在下一個窗體中顯示。

〈%@ Page Inherits="System.Mobile.UI.MobilePage" %〉

〈%@ Register TagPrefix="mobile" Namespace="System.Mobile.UI" %〉


〈Script language="VB" runat="server"〉

Sub Btn_OnClick(Src As Object, E As EventArgs)


‘move to the next mobile form

ActiveForm = frm2


‘display the name.

EnteredName.Text = "Your name is: " & YourName.Text

End Sub

〈/Script〉

〈mobile:Form id="frm1" runat=server〉

〈mobile:Label runat=server〉Your Name:〈/mobile:Label〉

〈mobile:TextBox runat="server" id="YourName" /〉

〈mobile:Command runat="server" id="btn" OnClick="Btn_OnClick"〉Ok
〈/mobile:Form〉


〈mobile:Form id="frm2" runat=server〉

〈mobile:Label runat="server" id="EnteredName" /〉

〈/mobile:Form〉

在以上的代碼中,創建了兩個窗體。第一個窗體的id為frm1, 第一個窗體的idfrm2。之所以使用這個方法是因為Mobile Form控件不支持name屬性,而支持id屬性。ASP.NET運行時就是通過這樣的方法來確認窗體的。在第一個窗體中,添加了一個lable控件,一個textbox控件和一個button控件。當點擊button時,服務器端的VB子程序(Btn_OnClick)就被調用。這對于那些熟悉VB的人來說就象在家里一樣親切。在處理VB子程序的事件里,通過給frm2設置ActiveForm方法來跳到下一個窗體。然后訪問定義在frm2中lable控件并設置用戶提交的值。


北斗有巢氏 有巢氏北斗