ASP.NET Tips To Increase Productivity and Simplify Maintenance – Part 6

ASP.NET Tips To Increase Productivity and Simplify Maintenance – Part 6

ASP.NET provides a robust framework for building Web applications that minimizes the amount of code that’s required to be written. Although most developers rely on Visual Studio or Web Developer Express when building applications, there’s no substitute for knowing the framework when it comes to increasing productivity. The more you know about built-in functionality in the .NET framework and ASP.NET, the less code you have to write, which ultimately makes your applications more maintainable.

This article outlines several different tips to enhance developer productivity and reduce the amount of code that needs to be written in many cases. Tips range from simple concepts, such as setting default focus on a control to creating your own FindControl() method. Although the tips focus on ASP.NET Web Forms, there is also information about Microsoft’s latest ASP.NET MVC framework as well. Let’s get started.

Build a Recursive FindControl() Extension Method

Although FindControl() is limited to finding immediate children of a parent control, there’s nothing to stop you from building a more robust method that can search for deeply nested controls. Both C# 3.0 and Visual Basic 9 allow extension methods to be created that can “extend” an existing class even if you don’t have access to the class’s source code. By using extension methods you can extend the Page class’s functionality quite easily and create a recursive FindControl() method. In fact, you can even make the method return a strongly-typed object so that you don’t have to perform casting operations as with the built-in FindControl() method.

To allow FindControl() to recursively search for children the following type of extension method can be written.

C#

Visual Basic

This code starts by attempting to find the target control in the parent container’s child controls collection using the built-in FindControl() method. If the control isn’t found, the FindChildControl() method is called recursively to locate the child based upon its ID. Because generics are used, the method is strongly-typed and automatically returns the appropriate type of child object if it is found.

To call the extension method the following code can be written. This example looks for a TextBox named txt-Target.

C#

No #1 Recommended ASP.NET Hosting

ASPHostPortal.com

ASPHostPortal.com  is the leading provider of Windows hosting and affordable ASP.NET Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.

HostForLIFE.eu

HostForLIFE.eu guarantees 99.9% uptime for their professional ASP.NET hosting and actually implements the guarantee in practice. HostForLIFE.eu is the service are excellent and the features of the web hosting plan are even greater than many hosting. HostForLIFE.eu offer IT professionals more advanced features and the latest technology. Relibility, Stability and Performance of  servers remain and TOP priority. Even basic service plans are equipped with standard service level agreements for 99.99% uptime. Advanced options raise the bar to 99.99%. HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24×7 access to their server and site configuration tools.

DiscountService.com.au

DiscountService.com.au is The Best and Cheap ASP.NET Hosting. DiscountService.com.au was established to cater to an under served market in the hosting industry web hosting for customers who want excellent service. DiscountService.com.au guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability. DiscountService.com.au has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. DiscountService.com.au is devoted to offering the best Windows hosting solution for you.