Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build Your Own Mobile Controls : Page 4

The mobile controls provided with ASP.NET are often insufficient. When that happens, a custom, from-scratch direct control is what you need. This article explains the ASP.NET mobile rendering model and guides you through the process of building your own custom mobile control.


advertisement
Using the Control in your Application
Add a reference to the control assembly by right clicking the "ASP.NET Mobile Controls" project, choose Add Reference, select the Projects tab, select the "DirectMobileClassLibrary," and click OK. Next open the "MobileWebForm1.aspx" page. The blank ASP.NET mobile form comes up. Select the HTML view at the bottom to view the HTML associated with this ASP.NET page. You need to register the control on the page by adding the following code at the top of the file "MobileWebForm1.aspx."

<%@ Register TagPrefix="myControl" Namespace="DirectMobileClassLibrary.myMobileControls"
Assembly="DirectMobileClassLibrary" %>

ASP.NET mobile controls have a TagPrefix of mobile, however because you have a new control you need to specify the TagPrefix(any name), and provide the Namespace and Assembly in which the control resides. The TagPrefix would be used to pre-fix your control on the page. Next you need to place the actual control on the page within the form tag.

<mobile:form id="Form1" runat="server"> <myControl:MultiLineTextBox id="MultiLineTextBox1" runat="server" Rows="3" Cols="20" Text="First Mobile Control"></myControl:MultiLineTextBox> </mobile:form>

You can also set the controls properties by specifying the rows, cols, and text as shown above.



Testing the Application
Hit F5 to run the application. The MobileWebForm1.aspx page loads, the control within it loads, and the adapter code kicks in to render the control as a TextArea control in your default browser. If you load up the PocketPC emulator that comes with VS.NET 2003 and try the application, it works beautifully even there as the emulator supports HTML rendering.

The ASP.NET mobile environment and the rendering technology is the most extensible technology from the Redmond stable. You can easily build any kind of controls and adapters from scratch, as I've done in this article. And, there are options to extend existing controls and support new devices. As a best practice, always check if the existing controls within ASP.NET can be extended to support any new requirement you may have.

This same rendering and extensibility technology is going to be available in all the new .NET controls in Whidbey, thereby allowing you to peacefully use any control, knowing it will render automatically to any device and enabling you build/extend a control for multiple devices. And that is something big to look forward to.



Sanjay Shetty is the CEO of Wireless Strategist & Consultants, a consultancy for mobility, design, architecture, and .NET migration. He is the Microsoft regional director in Mumbai, India. Reach him via .
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date