Webmaster''''s Guide to the Wireless Internet part 44 docx

10 271 0
Webmaster''''s Guide to the Wireless Internet part 44 docx

Đang tải... (xem toàn văn)

Thông tin tài liệu

402 Chapter 9 • Microsoft Mobile Internet Toolkit Figure 9.34 Image.aspx <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %> <%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <Mobile:Form runat="server"> <Mobile:Label>Photo of myself</Mobile:Label> <Mobile:Image runat=server alternateText="[My Photo here]"> <DeviceSpecific> <Choice Filter="isHTML32" ImageURL="myself.bmp" /> <Choice Filter="isWML11" ImageURL="myself.wbmp" /> </DeviceSpecific> </Mobile:Image> </Mobile:Form> Within the <DeviceSpecific> control, you have the <Choice> elements. In the preceding program, each choice element contains two attributes—Filter and ImageURL. So in this case, if the user were using a Web browser, the BMP file would be displayed, as shown in Figure 9.35. On the UP.SDK, the WBMP file would be selected, as shown in Figure 9.36. www.syngress.com Figure 9.35 Displaying the BMP File in a Web Browser 159_wg_wi_09 10/22/01 5:29 PM Page 402 Microsoft Mobile Internet Toolkit • Chapter 9 403 The <Choice> elements are evaluated according to the order in which they appear in the <DeviceSpecific> control. If none of the <Choice> elements evaluates true, the string “[My Photo here]” would be displayed.The Filter attribute con- tains values that are matched from the <deviceFilters> element in the web.config configuration file (see Figure 9.37). The web.config file contains the various device filters. Figure 9.37 shows a portion of the web.config file.A device may match several <filter>s. For example, a Web browser satisfies the isHTML32 and the prefersGif filter.The compare attribute of the <filter> element specifies the capability evaluated by the compar- ison evaluator and the argument attribute specifies the argument against which the capability should be compared. To illustrate using the preceding example, a WAP device will match the isWML11 filter, which will in turn match the second <Choice> element: <Choice Filter="isHTML32" ImageURL="myself.bmp" /> <Choice Filter="isWML11" ImageURL="myself.wbmp" /> Figure 9.37 Web.config <deviceFilters> <!— Markup Languages —> <filter name="isHTML32" compare="preferredRenderingType" argument="html32" /> <filter name="isWML11" compare="preferredRenderingType" argument="wml11" /> <filter name="isCHTML10" compare="preferredRenderingType" argument="chtml10" /> <!— Device Browsers —> <filter name="isGoAmerica" compare="browser" www.syngress.com Figure 9.36 Displaying the WBMP File in a WAP Browser Continued 159_wg_wi_09 10/22/01 5:29 PM Page 403 404 Chapter 9 • Microsoft Mobile Internet Toolkit argument="Go.Web" /> <filter name="isMME" compare="browser" argument="Microsoft Mobile Explorer" /> <filter name="isMyPalm" compare="browser" argument="MyPalm" /> <filter name="isPocketIE" compare="browser" argument="Pocket IE" /> <filter name="isUP3x" compare="type" argument="Phone.com 3.x Browser" /> <filter name="isUP4x" compare="type" argument="Phone.com 4.x Browser" /> <!— Specific Devices —> <filter name="isEricssonR380" compare="type" argument="Ericsson R380" /> <filter name="isNokia7110" compare="type" argument="Nokia 7110" /> <!— Device Capabilities —> <filter name="prefersGIF" compare="preferredImageMIME" argument="image/gif" /> <filter name="prefersWBMP" compare="preferredImageMIME" argument="image/vnd.wap.wbmp" /> <filter name="supportsColor" compare="isColor" argument="true" /> <filter name="supportsCookies" compare="cookies" argument="true" /> <filter name="supportsJavaScript" compare="javascript" argument="true" /> <filter name="supportsVoiceCalls" compare="canInitiateVoiceCall" argument="true" /> </deviceFilters> www.syngress.com Figure 9.37 Continued 159_wg_wi_09 10/22/01 5:29 PM Page 404 Microsoft Mobile Internet Toolkit • Chapter 9 405 Validation Controls There are quite a few validation controls available in the Microsoft Mobile Internet Toolkit SDK: ■ CompareValidator Compares two controls using a specified operator. ■ CustomValidator Allows customized validation of controls. ■ RangeValidator Validates the value of a control to ensure that it falls within a specified range. ■ RegularExpressionValidator Validates the value of a control by speci- fying a regular expression. ■ RequiredFieldValidator Ensures that a field is supplied a value. ■ ValidationSummary Displays the summary of all errors that occurred during the rendering of a form. To see how they work, let’s consider the example shown in Figure 9.38. Figure 9.38 Validation.aspx <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %> <%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <script language="vb" runat=server> Sub Submit_OnClick(sender as Object, e as EventArgs) if (Page.IsValid) then ActiveForm = Form2 Result.Text = "The month you have entered was " & month.Text end if End sub </script> <Mobile:Form id="Form1" runat=server> <Mobile:RangeValidator runat=server ControlToValidate="month" Type="Integer" www.syngress.com Continued 159_wg_wi_09 10/22/01 5:29 PM Page 405 406 Chapter 9 • Microsoft Mobile Internet Toolkit MaximumValue="12" MinimumVaLue="1"> The month is not correct. Please try again. </Mobile:RangeValidator> <Mobile:Label runat=server>Please enter your birth month</Mobile:Label> <Mobile:TextBox id="month" Numeric="true" runat=server/> <Mobile:Command OnClick="Submit_OnClick" runat=server>Submit</Mobile:Command> </Mobile:Form> <Mobile:Form id="Form2" runat=server> <Mobile:Label id="Result" runat=server/> <Mobile:Link Text="Back" navigateURL="#Form1" runat=server/> </Mobile:Form> In this example, we use the <Mobile:RangeValidator> control to validate the range of a number. <Mobile:RangeValidator runat=server ControlToValidate="month" Type="Integer" MaximumValue="12" MinimumVaLue="1"> The month is not correct. Please try again. </Mobile:RangeValidator> Once the number is entered and the button is clicked, the Submit_OnClick() subroutine is invoked.The IsValid property will validate the range of the number entered. If the validation fails, the message “The month is not correct. Please try again” is displayed; otherwise Form2 will be loaded. Sub Submit_OnClick(sender as Object, e as EventArgs) if (Page.IsValid) then ActiveForm = Form2 Result.Text = "The month you have entered was " & month.Text www.syngress.com Figure 9.38 Continued 159_wg_wi_09 10/22/01 5:29 PM Page 406 Microsoft Mobile Internet Toolkit • Chapter 9 407 end if End sub Figure 9.39 and Figure 9.40 show the output as displayed by the Pocket PC emulator and the UP.SDK, respectively. Paginations In an earlier section we saw the use of the <Mobile:List> control. It is possible that the list of items within the control might be long.Anyone who has written a WAP application can attest to the importance of keeping the list short, at least per screen.A common technique is to display the list in multiple pages, and as such this technique is commonly known as records paging. One of the great fea- tures of the Mobile API is its auto-paging capability. Consider the example shown in Figure 9.41. Figure 9.41 Paginate.aspx <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %> <%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> www.syngress.com Figure 9.39 Using the Validator Controls on the Pocket PC Figure 9.40 Using the Validator Controls on the UP.SDK Continued 159_wg_wi_09 10/22/01 5:29 PM Page 407 408 Chapter 9 • Microsoft Mobile Internet Toolkit <script language="vb" runat=server> Sub Select_Item (sender as Object, e as ListCommandEventArgs) End Sub </script> <Mobile:Form runat="server" id="form1" paginate="true" PagerStyle-NextPageText="Go to Page {0}" PagerStyle-PreviousPageText="Back to Page {0}"> <Mobile:Label runat="server" StyleReference="title" Text="Books in the .net Developer Series" /> <Mobile:Label runat="server" id="PageNo"/> <Mobile:List runat="server" id="titles" OnItemCommand="Select_Item"> <Item value="1" text="VB .net Developer's Guide"/> <Item value="2" text="XML Developer's Guide to Web Based EDI"/> <Item value="3" text="C#.net Developer's Guide"/> <Item value="4" text="ASP.net Developer's Guide"/> <Item value="5" text=".net Mobile Web Developer's Guide"/> <Item value="6" text="ADO.net Developer's Guide"/> <Item value="7" text="Web Services Developer Guide"/> </Mobile:List> </Mobile:Form> Our list contains seven items.When loaded using the UP.SDK, we see that the list is displayed in multiple cards (see Figure 9.42). www.syngress.com Figure 9.41 Continued Figure 9.42 Paginating a Form 159_wg_wi_09 10/22/01 5:29 PM Page 408 Microsoft Mobile Internet Toolkit • Chapter 9 409 To allow for paging, simply insert the Paginate attribute into the <Mobile:Form> control and set it to “true”.Additionally, the PagerStyle-NextPageText and the PagerStyle-PreviousPageText attributes allow you to set the message for displaying the next and previous page, respectively. <Mobile:Form runat="server" id="form1" paginate="true" PagerStyle-NextPageText="Go to Page {0}" PagerStyle-PreviousPageText="Back to Page {0}"> Calendar Control Apart from those regular controls like Label and Textbox, the Microsoft Mobile Internet Toolkit also includes some interesting controls like the Calendar and AdRotator controls.We will illustrate the use of the Calendar control in this section. Date selection is a commonly used feature of mobile applications and in the past, great efforts have gone into making date selection as easy and error-proof as possible. Instead of spending time in building the date selection module, the Mobile API has included the Calendar control. Consider the example shown in Figure 9.43. Figure 9.43 Birthdate.aspx <%@ Page Inherits="System.Mobile.UI.MobilePage" Language="VB" %> <%@ Register TagPrefix="Mobile" Namespace="System.Mobile.UI" %> <script language="VB" runat="server"> Sub date_Changed(sender as Object, e as EventArgs) message.Text = "So your birthdate is " & birthdate.SelectedDate End Sub </script> <Mobile:Form id="Form1" runat="server"> <Mobile:Label runat="server" styleReference="Title" Text="Tell me your birthdate!"/> <Mobile:Calendar id="birthdate" OnSelectionChanged="date_Changed" runat="server"/> www.syngress.com Continued 159_wg_wi_09 10/22/01 5:29 PM Page 409 410 Chapter 9 • Microsoft Mobile Internet Toolkit <Mobile:Label runat="server" id="message"/> </Mobile:Form> Figure 9.44 and Figure 9.45 shows how our code appears in the various emulators. When a date has been selected, the message in Figure 9.46 is printed. www.syngress.com Figure 9.43 Continued Figure 9.44 Using the Calendar Control on the Pocket PC Figure 9.45 Using the Calendar Control on the UP.SDK Figure 9.46 Printing the Birth Date 159_wg_wi_09 10/22/01 5:29 PM Page 410 Microsoft Mobile Internet Toolkit • Chapter 9 411 If you want the individual day, month and year printed instead (it is restricted to mm/dd/yyyy format), you can use the following properties: message.Text = "So your birthdate is " & birthdate.SelectedDate.day or message.Text = "So your birthdate is " & birthdate.SelectedDate.month or message.Text = "So your birthdate is " & birthdate.SelectedDate.year Accessing Data with ADO.NET Today, most applications of any respectable size involve database access in one way or another. Developers are familiar with using the ActiveX Data Objects (ADO) for accessing databases thorough OLE DB and ODBC. In anticipation of the increasing trend of distributed computing and the need to access data remotely, ADO.NET was evolved to support disconnected data access.Actually,ADO.NET is more of an evolution, rather than a revolution. If you are familiar with ADO, chances are you will find most of the concepts in ADO.NET similar. In the next section, we will take a closer look at ADO.NET and at how you can get started with it quickly. A Brief Look at ADO.NET If you are familiar with ADO, you should know that the Recordset object in ADO is no longer available in ADO.NET. Figure 9.47 sums up the architecture of ADO.NET. In place of the Recordset object, in ADO.NET there are two new objects for data access.They are: ■ Dataset ■ DataReader A Dataset object basically represents a complete set of data including related tables, constraints, and relationships among the tables.Think of a Dataset object as a static cursor in ADO, but instead of storing only a single table, it stores multiple tables.A DataReader object is used for reading records in a forward-only fashion. Think of a DataReader object as a forward-only cursor in ADO. www.syngress.com 159_wg_wi_09 10/22/01 5:29 PM Page 411 . 402 Microsoft Mobile Internet Toolkit • Chapter 9 403 The <Choice> elements are evaluated according to the order in which they appear in the <DeviceSpecific> control. If none of the <Choice>. isHTML32 and the prefersGif filter .The compare attribute of the <filter> element specifies the capability evaluated by the compar- ison evaluator and the argument attribute specifies the argument. operator. ■ CustomValidator Allows customized validation of controls. ■ RangeValidator Validates the value of a control to ensure that it falls within a specified range. ■ RegularExpressionValidator

Ngày đăng: 04/07/2014, 02:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan