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

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

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.

Strongly Typed Access to Cross-Page Postback Controls

ASP.NET 2.0 and higher supports the ability to post data from one page to another using cross-page postback functionality. This is useful when you don’t want a page to postback to itself. For example, you may have a search user control defined in a master page, and when the end user searches, you want to take them to a search results page.

The built-in cross-page postback functionality in ASP.NET works great out of the box but doesn’t provide strongly-typed access to controls in the previous page. Out of the box, you’ll normally have to resort to FindControl() method calls to locate the controls. There’s another option that can be used, though, to access controls in a strongly-typed manner, which minimizes the amount of strings in your code and allows the compiler to catch errors more easily.

If you have a page called Default.aspx that exposes a public property that returns a Textbox defined in the page, the page that data is posted to (let’s call it SearchResults.aspx) can access the property in a strongly-typed manner by adding the PreviousPageType directive into the top of the page:

By adding this directive, the code in SearchResults.aspx can access the TextBox defined in Default.aspx in a strongly-typed manner. The following example assumes the property defined in Default.aspx is named SearchTextBox.

C#

Visual Basic

This code obviously only works if the previous page is Default.aspx. PreviousPageType also has a TypeName property as well where you can define a base type that one or more pages derive from to make this technique work with multiple pages.

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.