Building Microsoft ASP.NET Applications for Mobile Devices, Second Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Building Microsoft ASP.NET Applications for Mobile Devices, Second Edition [Electronic resources] - نسخه متنی

Andy Wigley; Peter Roxburgh

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید






The MobileCheckbox Control


The MobileCheckbox control, written by Mike Bohlander of Microsoft, implements simple check box functionality. MobileCheckbox is supplied with device adapter functionality to allow it to operate on HTML, cHTML, and WML browsers. Figure 7-4 shows how the control looks on the HTML browser used on the Microsoft Smartphone and on a WML browser.


Figure 7-4: MobileCheckbox control shown on an HTML browser and a WML browser


Configuring Your Application


You must configure your application to use the new device adapters for the MobileCheckbox control, as described in the section "Configuring Your Application to Use Custom Controls" earlier in this chapter. Add the following <device> configuration XML inside the <mobileControls> tags in an application's web.config configuration file:

<configuration>
<system.web>
<mobileControls>
<device name="MobileCheckboxHtmlDeviceAdapter"
inheritsFrom="HtmlDeviceAdapters">
<control name="MobileCheckbox.Checkbox,MobileCheckbox"
adapter="MobileCheckbox.HtmlCheckboxAdapter,MobileCheckbox"/>
</device>
<device name="MobileCheckboxWmlDeviceAdapter"
inheritsFrom="WmlDeviceAdapters">
<control name="MobileCheckbox.Checkbox,MobileCheckbox"
adapter="MobileCheckbox.WmlCheckboxAdapter,MobileCheckbox"/>
</device>
<device name="MobileCheckboxChtmlDeviceAdapter"
inheritsFrom="ChtmlDeviceAdapters">
<control name="MobileCheckbox.Checkbox,MobileCheckbox"
adapter="MobileCheckbox.ChtmlCheckboxAdapter,MobileCheckbox"/>
</device>
</mobileControls>
</system.web>
</configuration>


Syntax


The MobileCheckbox control is used declaratively, as shown in the following code:

<%@ Register TagPrefix="mobCB" Namespace="MobileCheckbox"
Assembly="MobileCheckbox" %>
<mobCB:Checkbox
runat="server"
id="id"
Alignment="{NotSet|Left|Center|Right}"
BackColor="backgroundColor"
BreakAfter="{True|False}"
Font-Bold="{NotSet|False|True}"
Font-Italic="{NotSet|False|True}"
Font-Name="fontName"
Font-Size="{NotSet|Normal|Small|Large}"
ForeColor="foregroundColor"
StyleReference="StyleReference"
Wrapping="{NotSet|Wrap|NoWrap}"
AutoPostBack="{True|False}"
Checked="{True|False}"
OnCheckedChanged="EventHandlerMethodName"
TextAlign="{Left|Right}"
Text="LabelText"
</mobCB:Checkbox>


Properties


Table 7-1 describes the properties and events you're most likely to use with the MobileCheckbox control.



























Table 7-1: Significant Properties and Events of the MobileCheckbox Control


Property/Event


Type


Description


AutoPostBack


True|False


Gets or sets a value indicating whether the MobileCheckbox state is automatically posted back to the server when the control is clicked. Default is False. This property applies only to HTML browsers.

If AutoPostBack is false, then you must have another control on the same Form to make the postback to the server, such as a Command control.


Checked


True|False


Gets or sets a value indicating whether the MobileCheckbox control is initially checked. Default is False.


TextAlign


System.Web.UI.We bControls.TextAlign enumeration: Left|Right


Use this property to specify the alignment of the text label associated with the MobileCheckbox control. You can specify whether the text label appears to the right or left of the check box. Default is Left. Use the Text property to specify the label text.


Text


String


Use this property to set or get the text label associated with the MobileCheckbox control.


CheckedChanged (Event)


Event handler method


Set to the name of an event handler method of signature OnCheckedChanged(Object sender, EventArgs e). This event fires when the Checked property of the Checkbox changes.






More Info

For more information about the commonly used properties and events inherited from the MobileControl class, refer to Table 4-1 and Table 4-2 in Chapter 4.



Using the MobileCheckbox Control


The example application shown in Listings 7-1 and 7-2 uses the MobileCheckbox control to implement a true/false quiz game. The application produces the output shown earlier in Figure 7-4.

Listing 7-1: Source for default.aspx in MobileCheckboxExample






<%@ Register TagPrefix="cc1" Namespace="MobileCheckbox"
Assembly="MobileCheckbox" %>
<%@ Page language="c#" Codebehind="default.aspx.cs"
Inherits="MSPress.MobWeb.CheckboxEx._default"
AutoEventWireup="false" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<mobile:Form id="Form1" runat="server" title="Facts about Wales">
<mobile:Label id="Label3" runat="server" StyleReference="title">
Facts about Wales:</mobile:Label>
<mobile:Label id="Label2" runat="server">
True or False?:</mobile:Label>
<cc1:Checkbox id="Checkbox1" runat="server"
Text="Capital is Cardiff"></cc1:Checkbox>
<cc1:Checkbox id="Checkbox2" runat="server"
Text="Highest mountain is Snowdon"></cc1:Checkbox>
<cc1:Checkbox id="Checkbox3" runat="server"
Text="Favorite sport is rugby"></cc1:Checkbox>
<mobile:Command id="Command1" runat="server">Next</mobile:Command>
</mobile:Form>
<mobile:Form id="Form2" runat="server" title="Result">
<mobile:Label id="Label1" runat="server"
StyleReference="title">Result</mobile:Label>
<mobile:Label id="result" runat="server">Label</mobile:Label>
</mobile:Form>











Listing 7-2: Code-behind file default.aspx.cs in MobileCheckboxExample






using System;
using System.Web.UI.MobileControls;
namespace MSPress.MobWeb.CheckboxEx
{
public class _default : System.Web.UI.MobileControls.MobilePage
{
protected MobileCheckbox.Checkbox Checkbox1;
protected System.Web.UI.MobileControls.Command Command1;
protected System.Web.UI.MobileControls.Form Form2;
protected MobileCheckbox.Checkbox Checkbox2;
protected MobileCheckbox.Checkbox Checkbox3;
protected System.Web.UI.MobileControls.Label result;
protected System.Web.UI.MobileControls.Form Form1;
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Command1.Click +=
new System.EventHandler(this.Command1_Click);
}
private void Command1_Click(object sender, System.EventArgs e)
{
int correct = 0;
if (Checkbox1.Checked) correct++;
if (Checkbox2.Checked) correct++;
if (Checkbox3.Checked) correct++;
result.Text = "You got " + correct.ToString() + " correct";
ActiveForm = Form2;
}
}
}











/ 145