ASP.net 2.0 property rewriting and templating of mobile development

Source: Internet
Author: User
Tags filter case statement header switch case

This article focuses on customizing ASP.net web movers for specific hardware devices, and using templates to customize controls such as form and panel. This attribute is overridden by attributes to enable the ASP.net Web mover to specify the property values of its controls for a particular hardware based on the hardware capabilities of the mobile device. For example, an application might require a Label control to display longer text on some devices and shorter text on other devices. This requires that we provide a set of properties for each control that the application can override for each device. All ASP.net mobile controls have the default appearance and layout. For ASP.net mobile controls, you can change the default appearance of mobile controls by setting properties or using styles. You can also use templates to customize the appearance of some mobile controls. This chapter will also focus on templates and template sets, and how they are used.

Customize the way

In the previous topics, we mentioned how to use device filters to customize a particular device. In addition, we can use templating technology and property rewrite features to enable you to customize your application so that the controls are rendered differently for specific device types. If you use any of these custom methods for a control in the. aspx page, you can use a mobile control syntax named Devicespecific/choice constructs. The Devicespecific/choice construct is typically a device-specific set of option templates and an option is specified within the control across multiple alternative content. For example, the following code is the declaration syntax for a label control that contains a Devicespecific/choice construct that identifies whether the current browser supports HTML.

<mobile:Label id="Label1" runat="server" Text="Default text">
<DeviceSpecific>
<Choice Filter="isHTML32" Text="Text for selected devices" ></Choice>
</DeviceSpecific>
</mobile:Label>

Where the Filter property specifies a device filter whose name is IsHTML32, which is used to identify whether a mobile device has a built-in HTML browser. If you have an HTML browser built in, the text for selected device will be applied to the label control. On the contrary, no display is made. As shown in the preceding code, the typically contains one or more elements, each containing a property that specifies how to compute the options based on the capabilities of the target device. The runtime calculates each option in turn and uses the first option that is successfully computed (this is very similar to the switch case statement in C #).

Before you begin to learn how to define a device filter, let us first understand some basic concepts, such as the specific meaning of attribute overrides and templating.

Property Overrides

In general, the ASP.net Web mobile program We develop is not aimed at a specific device, but can be presented on almost all hardware devices by adapting to the different hardware characteristics of the mobile device.

But because of the different brands and models, there are inevitably some differences between these mobile devices. Examples include supported colors, screen sizes, input features, and the markup language used by browsers. As mentioned earlier, ASP. NET controls can be supported by almost all hardware devices because they themselves have adaptive functionality, and the property values set by the control are also associated with the ASP.net control applied to the specific application, and do not differ by the hardware device for different attribute values. However, in some cases you may discard the default rendering, using a custom rendering. A typical example is the display of characters, for example, we use a Label control for string display, and on some smaller screen devices, each line displays fewer characters, so we can set the control's Text property to "We use asp.net", and for some large-screen devices, We can set the Label control's Text property to "we use asp.net to build a full-featured mobile application," precisely because of the property rewrite feature, we can use the above method to build a different mobile device hardware features to make the best presentation asp.net Web Mobile applications.

Template

Mobile controls such as Form, Panel, List, and ObjectList are templated controls. Developers often use templates to change or enrich the appearance or content of an application. For example, if you specify and select a header or footer template for a form control, the markup that is contained in the template is added to the content of the form, rendered as a header or footer, respectively. Note that templates are different from styles, and templates define the content and controls to display. The template is rendered when the application renders the control to which the template is attached. While styles specify the appearance of content and controls, your application can use styles without using templates, and it can also apply styles to your defined mobile controls within a template. In addition to templates, ASP. NET mobile controls on this basis, a new model is extended and the concept of template set is introduced. A template set is a collection of templates. However, a single templated control might reference multiple template sets, and each template set has a different device-specific condition. The specific implementation of the template set will be detailed in the following chapters.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.