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

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


اندازه قلم

+ - پیش فرض

حالت نمایش

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

Common Mobile Controls Behavior

All the mobile Web Forms control classes descend from, and inherit much of their behavior and characteristics from, the System.Web.UI.MobileControl base class (which itself inherits from System.Web.UI.Control). In this and the following three chapters, we'll discuss each of the mobile controls, describing their unique capabilities. Because these controls inherit certain aspects of their behavior—primarily style and context—from the MobileControl base class, we won't bother repeating these capabilities and features in every control's definition. Instead, we'll describe these common characteristics here.

Every control contains a System.Web.UI.MobileControls.Style object. However, this Style object is not exposed through public members. Instead, for each style property, the MobileControl has a publicly accessible property that internally references the privately contained style. For example, every mobile control exposes a Font property, which is actually a property of the privately contained Style object. (Note that the Font property of the Style object exposes a System.Web.UI.WebControls.FontInfo object, which has Bold, Italic, Name, and Size properties.). In code, you can get and set properties of the contained FontInfo object using the syntax Font.Italic. However, in ASP.NET server control syntax, properties of contained objects such as the FontInfo object can be set directly through attributes of the server control syntax by using a ContainedObject-Property notation. For example, set the Italic property of the contained FontInfo object using the attribute name Font-Italic:

<mobile:Label Font-Italic="True" Text="Some text"></ mobile:Label>


You set the common properties of the mobile controls using the following server control syntax:

<!-- Events -->

The meaning of individual properties is given in next section, and the meaning of the events is given in Table 4-2.

Common Properties and Events

"Syntax" section, apart from exceptions already mentioned, such as subproperties of the Font property.

Table 4-1: Properties Common to All Mobile Controls






Alignment of the control in the display. If NotSet, Alignment is inherited from the parent container control (the Form or Panel control within which the control is positioned). If the alignment isn't defined in any containing control, the default is left-aligned.


None|hexadecimal RGB values|standard HTML color identifiers|color constants

The background color used for the control. The default is Color.Empty, meaning the system default applies. Unlike other properties, BackColor is not inherited from its container control.



The default is True, which means that a trailing break is rendered after the control. Set to False to request that the following control or literal text is rendered on the same line. Note that the runtime might not observe this property setting if it results in an inappropriate layout on a particular device.


Valid font name

This property contains the name of the specified font used to display text in the control. The default font name is an empty string, indicating that the Font used is inherited from its containing control. If the font name isn't defined in any containing control, the default is the system font of the server.


FontSize.NotSet| Normal| Small| Large

The font will be rendered using the requested size, subject to the capabilities of the client device. If the value is set to NotSet, the property is inherited from the container control.



Specifies whether the text is boldface. If NotSet, the property is inherited from the container control.



Specifies whether the text is italic. If NotSet, the property is inherited from the container control.


None|hexadecimal RGB values|standard HTML color identifiers|color constants

The color used for text display in the control. If None, the color is inherited from the container control. If no container specifies the ForeColor property, the system default applies.


String value

If you assign an ID to the control in the server control syntax, you can use the ID to refer to the control in your code-behind module. If you don't assign an ID, the system supplies one. The Microsoft Visual Studio .NET Mobile Internet Designer always assigns an ID to controls when you drag them from the Toolbox onto a form.


Null|named style

Styles are named collections of style attributes stored in a style sheet. (You'll learn more about styles and style sheets in Chapter 8.) Three system-defined styles exist: title, in which the text of the control is presented with emphasis, typically a boldface and large font size; subcommand, which uses a small font size to deemphasize the text; and error, which appears in a red font on those devices that support color.


System-assigned value

This is a nondeclarative property. The system generates this value when it processes the page to assign a unique name to every control in the page. The generated name consists of the ID property of the control, preceded by the IDs of any containing controls that are Naming Containers, for example MyList:ctrl0:Label1. (See Chapter 9 for a description of naming containers.)



A control that isn't visible still exists as a programmable object on the page, but it isn't rendered to the client device.


Wrapping. NotSet|Wrap| NoWrap

Determines whether the text wraps onto the next line. If wrapping is disabled, the text will extend beyond the right screen margin. Browsers such as Pocket Internet Explorer allow you to scroll to the right to read wide text. Many Wireless Markup Language (WML) browsers allow right-scrolling using keypad buttons or apply marquee scrolling, meaning that the line in question automatically scrolls across and then back so that the user can read it. If the property is set to NotSet, the value is inherited from the container control.

Table 4-2: Events Common to All Mobile Controls




Occurs when the control binds to a data source.


Occurs when a control is released from memory, which is the last stage of the server control life cycle when an ASP.NET page is requested.


Occurs when the control is initialized, which is the first step in its life cycle. When the Init event occurs, ViewState has not been restored yet (ViewState stores properties of the control saved at the end of the previous request), so you should not try to access properties of another control in an event handler for this event.


Occurs when the control is loaded into the MobilePage object. You can access ViewState information and other controls in the mobile page from this event.


Occurs when the control is about to render to its containing MobilePage object.


Occurs when the control is unloaded from memory.

Many of the style properties have a default value of NotSet. Controls inherit many of their style attributes from any container control. Therefore, if you set a foreground color on a Form control, all the controls it contains will inherit that foreground color. However, defining a control style attribute directly overrides any inheritance. The value NotSet indicates that the control will inherit the property value, and this value is displayed in the Properties window in Visual Studio .NET or returned when you query a style property value in code, so you can easily determine whether the control's style is inherited or is set explicitly.

Style attributes of a control can also be set differently on different client devices by using DeviceSpecific/Choice constructs or by using templates on the controls that support them. These techniques allow you to apply device-specific behavior to your application at run time so that specific types of requesting devices use different style attributes from others. For example, you might want to display a different font size or text color on an HTML browser than you do on a compact HTML (cHTML) device. You'll learn more about both these techniques in Chapter 9.

Event handlers for all these events take two arguments: an argument of type Object that identifies the sending control, and an argument of type System.EventArgs:

EventHandlerMethodname(Object sender, EventArgs e)


The different ways in which you can wire up event handlers to events was described in the topic Wiring up Event handlers and Events in Chapter 3. One possible technique is to use ASP.NET server control syntax, for example:



The "Syntax" section for each mobile control in Chapter 4 through Chapter 7 includes events in the list of valid attributes to show how you would wire up the event using server control syntax. However, be aware that if you use Visual Studio .NET to create your ASP.NET mobile Web applications, it does not use server control syntax to wire up event handlers, but instead wires them up in code. Refer to Chapter 3 for an explanation of the different methods of wiring up event handlers.

/ 145