Products
Database Search Solution (New Version) Search Control SEO Pager Highlighter Shortcut Controls Crypt Package Free ASP.NET Controls
Geotargeting Component ASP.NET Media Player Control Flash Video Player Control Services
ASP.NET Telecommute Jobs Free IP Location Lookup Test .Net Regular Expressions CSS/Table/DIV Page Layouts Custom Programming Article Sites Master List |
Support Mobile Devices in ASP.NET (Advances Topics)In the last article, I explained the basics of supporting mobile devices in ASP.NET. After reading that article, I hope you would have grasp the basics of writing mobile pages and using mobile controls for developing mobile specific web sites. After reading this article, the reader must be having knowledge of:
How to customize mobile pages by Device TypeWe discussed in the last article that ASP.NET renders customized output for different browsers. However, if you are including complex web controls like Calendar or you are involving graphics in your pages, you have to build some special logic since many mobile devices do not support all the features. It is an easy process to detect exact capabilities of a mobile device by using MobileCapabilities class. This class is enriched with number of properties. Using these properties, we can get such capabilities of devices as screen dimensions, JavaScript & VBScript support. Some of these properties are:
In traditional ASP.NET pages, the same role is played by BrowserCapabilities class. Request.Browser is an object of this class and can be used in the following way:
Using this knowledge, Can you guess how to use Request.Broswer in mobile pages? Code bellow shows its use.
TypeDescriptor object is used to collect complete list of properties by using GetProperties method. In this case, all properties returned by the Request.Browser are collected by this object and assigned to "p". The List would display all the properties which Request.Browser returns. This is done by binding this list to "p". The PropertyDescriptorCollection contains a property Name to access the name of each target object's properties. To bind the list control to "p", DataTextField property has been named as Name. In short, Request.Browser enlists many properties of the device which is stored in the object of PropertyDescriptorCollection. To bind this object with the list control, you have to name the DataTextField property of control as Name. Listing above is useful when you want to analyze many capabilities of device. If you want to check a capability such as VBScript support, the HasCapability of Request.Browser can be used in the following way:
There is another method which relies on defining device filters in web.config file and later using this file. I assume the method described above suffices developers need for checking device capabilities. Using Cascading Style sheets in mobile pagesBy using StyleSheet Control and mobile web control attributes, custom styles can be applied easily in ASP.NET. Below are some mobile web controls:
The StyleSheetControl contains many style sets. Each set can specify the Foreground color, name, size etc of the text. When in a form, StyleReference is assigned a particular style set; this means the text in that form would be displayed using the defined font specifications in Style set. To experience a concrete example, see code listing bellow:
This is not encouraging to know that many mobile devices do not support CSS. We would wait for advancement in features that common mobiles have. As I said before, ASP.NET offers many powerful features to develop mobile pages. However, Mobiles are generally lacking features like Graphics, JavaScript, Cookies, CSS support etc. Developing User Friendly Mobile Pages:In any system, be its software or else; usability of the system is key. Increasing the usability of your product should be a main design consideration. First thing is, you should understand the ViewState control. By enabling the ViewState property, values of other controls are preserved and displayed when the same page is rendered again. For example, if you have enabled ViewState for all controls in user registration page, all the values of controls (e.g. value for User name text field, Gender's check box) would be preserved if the page shows some input error (like user name already taken) and is rendered again. All the values that you have entered before would be there in their respective fields. All the values of controls are stored in one hidden field which is for ViewState and is named as _VIEWSTATE. It would be something like:
The value is encrypted value of all controls. Now, I discuss mobile pages in specific The problem is, mobile devices transmit information at very slow rate. Using ViewState this way would slow down performance of your mobile pages significantly. ASP.NET mobile handles this issue by storing View State in Session. But the problem is, ASP.NET session uses cookies and many mobile devices do not support cookies. One possible solution is the use of HiddenVariables collection of Form class. This collection can be stored to keep information about the users. The information can be stored and retrieved in the same way as we deal with Session object. That is,
An example is:
In short, Use HiddenVariables collection of Form class instead of ViewState in session. There are many things which are common across diversity of mobiles. Every mobile device contains a Back button and scroller to scroll through the contents of the page. Alphanumeric input is difficult in almost all mobile devices. User friendly sites can be made using knowledge of common features. Developing a website with multiple small pages rather than one lengthy page is good option. Users would not mind pressing Back button to select and access other link but scrolling down to browse through a page seems a hectic task. So, divide your homepage in logical divisions. Some mobile devices do not render graphics. Try avoiding the graphics which are essential for understanding the page. Text-Only mobile phones would skip graphics. One emphasis that I made previously about the power of ASP.NET in developing mobile pages is not always true. In real world scenario, there are mobiles carrying different capabilities. There are mobiles which do not support JavaScript, Cookies etc while ASP.NET offers different features to make use of them. Similarly, you can create mobile pages that can use different technologies like ADO.NET, XML, Web services etc.
Summary
Tutorial toolbar: Tell A Friend | Add to favorites | Feedback | |