Archives

Archives / 2011
  • Dealing with Profile Access in ASP.NET MVC Applications

    ASP.NET services such as Profile are available to MVC applications too and developers can make use of them when needed. While developing a Web Forms based website project developers can access profile properties in a strongly typed fashion. This strongly typed nature comes from the ProfileCommon class that is generated automatically in such projects. ASP.NET MVC and Web Application projects, however, lack this handy and useful feature. In this article you will learn how to access user Profile in ASP.NET MVC applications and also an alternative to overcome this limitation.

  • Implementing Website Pinning in ASP.NET

    Internet Explorer 9 introduced a new feature - Pinned Websites - that allows you to create a shortcut to a website on Windows 7 taskbar. A pinned website, however, exposes much more functionality than an ordinary shortcut. Normally to launch a website, the user needs to open a browser instance, type in website URL in the browser address bar and then navigate to the required part of the website. Pinning a website allows the user to launch it much like a desktop application. The user can simply click on the icon of the pinned website or select a specific option from a menu and start working with the website. Since a pinned website is always visible on the taskbar, website pinning also grabs constant user attention. This can result in significant increase in the usage of the website for obvious reasons. No wonder that every ASP.NET developer would like to take advantage of this feature in their websites. To that end this article discusses various steps involved in enabling pinning for your website. It also illustrates creating static and dynamic task entries and discusses a few other scenarios specific to ASP.NET.

  • Aggregating RSS Feeds - Quick code sample

    .NET framework provides classes to read and write RSS and ATOM feeds. I already wrote a couple of articles illustrating the use of these classes. These classes reside in System.ServiceModel.Syndication namespace and primarily work with one feed at a time. Sometimes, however, you need to aggregate multiple feeds to create a single feed. The code sample below shows you how to accomplish this in an ASP.NET web form.

  • HTML5 Form features you should know

    In the past few articles I discussed HTML5 features that every ASP.NET developer should be aware of. In this article I will focus on HTML Forms and discuss some enhancements that make your life easy. Merely using various input types is just one part of the story. You should also know HTML5 features that are applicable to the form as a whole. This article illustrates some such features. All the examples use Chrome as a browser but many can be tested in Safari, Opera and others.

  • Introduction to HTML5 for ASP.NET Developers

    More and more web applications are harnessing the power of client side features of a browser. To that end HTML5 has many features to offer web developers. HTML markup, JavaScript and CSS have become more powerful and flexible than ever before. ASP.NET Developers must be well-versed with HTML5 features because all of the leading browsers are aggressively supporting them and newer web applications are bound to rely heavily on them. This article is intended to give you an overview of some key features of HTML5 from a developer's perspective. We won't go into too much detail of new HTML tags, CSS3 and such "markup" level features, instead we will focus on features more appealing to web developers.

  • Working with HTML5 Canvas

    One of the reasons for the popularity of the web is the graphical user interface offered to the end users. Images, animations, fonts and other interactive effects make a website appealing from an end user's perspective. However, one limitation that website developers often encounter is drawing graphics in the browser. As a solution, developers often resort to Flash or Silverlight based plug-ins or generate graphics on the fly at server side and then send it to the client. HTML5 does a great job in client side graphic rendering by offering what is known as canvas. The actual drawing can be carried out using JavaScript code and certain new graphic objects. Understanding HTML5 canvas and associated JavaScript objects is important for any ASP.NET developer and this article teaches you just that.

  • Using HTML5 input types in ASP.NET

    HTML5 introduced several new input types for <INPUT> element. These new input types include number, range, email, url, color, date, datetime and a few more. Though these types are not fully supported by all desktop browsers any ASP.NET developer should know them because newer browser versions will definitely support them. In this article you will learn the basics of using the new input types. More importantly you will also learn to use them with ASP.NET Web Forms and ASP.NET MVC applications.

  • Introduction to Entity Framework Code First

    Entity Framework (EF) allows you to program against a model instead of dealing with a database directly. In EF 4.0 (that ships with .NET 4.0) you typically design a model from an existing database visually, using a designer provided for that purpose. EF 4.1 builds on top of what EF 4.0 provided and allows you to create models directly at code level. That means instead of creating any database and then using a designer to define models, you create plain .NET classes and then use EF 4.1 techniques to make them EF models. This approach is referred as Code First because you focus on the source code of the model classes first. Once the models are ready Code First can also generate database tables out of those model classes. In this tutorial you will learn the basics of developing an application using Entity Framework Code First.

  • Emitting Exceptions from LINQ to SQL classes in ASP.NET MVC Validation Summary

    Recently while developing a sample application in ASP.NET MVC, I came across a peculiar situation. There was a LINQ to SQL class with several extensibility methods defined (OnXXXXChanging kind of methods where XXXX is the name of a property). The methods were performing some validation checks and in case of any violation were throwing exceptions. The LINQ to SQL class was working fine. However, at some places I wanted to display the validation errors (thrown by the class as exceptions) on the ASP.NET MVC views. That is where the problem began. No matter what exception you throw in the class the Validation Summary never displays the error message.

  • Generating Code Using Text Template Transformation Toolkit (T4)

    Many times developers come across situations where they need to write similar code over and over again. Automating the generation of such boilerplate code not only reduces the time spent but also reduces the chances of errors while doing such monotonous development. To help developers achieve this goal, Visual Studio 2010 includes what is known as Text Template Transformation Toolkit (T4). T4 templates are text files that specify the structure of the code or markup to produce. T4 comes with its own set of directives and blocks, which allow you to you define the boilerplate for code generation. This article introduces you to T4 basics and familiarizes you with the various parts of a T4 template.

  • Using Visual Studio Debugger Attributes

    Visual Studio provides a rich debugging experience to developers, helping them write robust and bug free code. In simple projects, the inbuilt facilities of Visual Studio debugger may be sufficient for your purpose, however, while debugging complex projects you may want to enhance the debugging experience further. Luckily, Visual Studio offers debugger attributes that help you do just that. Debugger attributes allow you to customize the way Visual Studio debugger steps through your code and also the display of your types. This article explains some of the important debugger attributes along with debugger type proxies and visualizers.

  • Create a Simple Task-List Application Using ASP.NET, WCF, and jQuery, Part 2

    In the first part of this two-part series, published in the June 2011 issue, we developed a Windows Communication Foundation (WCF) service that takes data in and out of the Tasks table. We created a web form for displaying the tasks in a tabular format using the jQuery Templates plug-in. Finally, we developed a DatePicker plug-in to pick due dates. In this second part, we'll make the task-list application functional by writing jQuery code, including a few helper functions, code to call WCF service methods, and code to filter the task-list table.

  • Using DynamicObject and ExpandoObject

    C# is primarily a statically typed language. That means the compiler needs to know in advance about the data type of a variable. In the absence of this information, the compiler will throw a compilation error and will refuse to compile the code. In spite of the advantages offered by the statically typed languages, dynamic languages have their own place in application development. For example, most of the web sites developed today make use of JavaScript in some way or the other. Languages such as Python and Ruby are also popular amongst developers. The C# language now supports dynamic features through Dynamic Language Runtime (DLR). Part of these features include dynamic types, DynamicObject Class and ExpandoObject Class. This article explains these features and provides examples illustrating how these features are used.

  • Working with URL Routing in ASP.NET Web Forms

    While developing web sites, at times you require that the URLs being used are not mapped to any physical file. For example, you might be building a blog engine that stores all blog posts in a SQL Server database but while displaying these posts you want URLs to be SEO friendly. In such cases the resource pointed to by the URL has no physical existence. That's where the URL Routing features of ASP.NET come to the rescue. In addition to creating SEO friendly URLs these features also help you render easy to remember URLs. ASP.NET MVC relies heavily on the URL Routing feature. However, it is also possible to use URL Routing in web forms. In this tutorial you will learn just that.

  • Working with Query Extender control

    Many ASP.NET websites allow users to filter data presented to them on the basis of certain conditions. A general approach used in such cases is to re-construct the database query again and again for each such filter parameter. Though this works well as far as end user requirements are concerned, it can make your code a bit tricky and cumbersome to manage. This is because you need to manipulate the WHERE parameters of the data source control under consideration (LINQ Data Source for example) in your source code. That is where the Query Extender control comes handy. The ASP.NET Query Extender server control allows you to filter data retrieved from a data source without changing the underlying query. It does so using a declarative syntax without any need to programmatically manipulate query parameters. This article explores the Query Extender control with the help of several examples.

  • Create a Simple Task List Using ASP.NET, WCF, and jQuery, Part 1

    Maintaining a task list (or to-do list) is a common time management technique that keeps track of work items to be completed along with their priority and current status. No wonder that task manager is often an integral part of web and desktop calendaring applications. In this two part article we will build our own task list application using jQuery, ASP.NET and WCF. Though simple our task list application will illustrate how jQuery can interact with server data through WCF services. We will also get to use several jQuery concepts such selectors, AJAX calls and plug-ins.

  • Understanding ASP.NET MVC Model Binding

    ASP.NET MVC model binding allows you to map and bind HTTP request data with a model. Model binding makes it easy for you to work with form data because the request data (POST/GET) is automatically transferred into a data model you specify. ASP.NET MVC accomplishes this behind the scenes with the help of Default Binder. This article discusses how model binding works for various types of models viz. simple types, class types and lists. It also shows how to create a custom model binder if situation calls for it.

  • Validating Data in ASP.NET MVC Applications

    Validating data entered by the user is one of the most common tasks in web applications. As far as ASP.NET MVC is concerned there are various ways to accomplish this task. As a web developer you should be aware of these options so that depending on your requirement you need to pick the appropriate one. This article discusses many of the available options and also shows in step-by-step manner how these options can be put to use in your ASP.NET MVC application.

  • Improving Performance of ASP.NET MVC Applications Using Caching Features

    Developers frequently look for opportunities to squeeze the last drop of performance from their web applications. In ASP.NET web forms and user controls Output Caching is a very popular performance enhancement technique. The same technique can also be implemented in ASP.NET MVC applications. Upon applying the Output Caching techniques, the page output is cached so that further requests are served with the cached copy rather than processing and generating it again and again. In this article you will learn how Output Caching is used in ASP.NET MVC applications along with some considerations involved in the process.

  • Using Microsoft Ajax Minifier Tool to Minify JavaScript Files

    The increased use of JavaScript and libraries based on JavaScript (such as ASP.NET AJAX and jQuery) results in a considerable amount of JavaScript being downloaded on the client side. The need for large amounts of JavaScript to be downloaded may result in your website getting a performance penalty for obvious reasons. In such cases it is recommended to reduce the size of JavaScript files by using minification techniques. To that end Microsoft Ajax Minifier, a tool to compress JavaScript and CSS files, can greatly reduce the size of such files thus improving the performance of your web application. In this article you will learn the basics of using Microsoft Ajax Minifier tool and certain programming recommendations to get most out of the minification process.

  • Dynamic data in existing data controls

    In a traditional data driven web site, you need to individually create web forms necessary to get the data in and out of the database tables. ASP.NET Dynamic Data features allow you to automate this functionality. ASP.NET Dynamic Data allows you to create extensible data driven web applications with little or no coding from your side. ASP.NET Dynamic Data automatically reads the database schema for you and generates data display and data entry pages on the fly. You can, of course, customize the resultant application if needed. The ASP.NET Dynamic Data Web Site project templates create a base project with necessary web forms and user controls that you can customize to suit your needs. However, in some cases creating a separate project is undesirable and you may want to integrate the Dynamic Data features with an existing web site. In this step-by-step article you will learn how this can be accomplished.

  • Using Microsoft Ajax CDN to Refer ASP.NET AJAX and jQuery Files

    Modern web applications rely heavily on client side scripting to provide rich user experience. To that end ASP.NET AJAX and jQuery are popular choices amongst ASP.NET developers to render rich user interface. These libraries make use of client script physically stored in JavaScript (.js) files. When a client accesses a web form that makes use of these libraries the client browser first needs to download the required library files on the client side and then execute the client script. Developers often store these JavaScript files as a part of their web site and then refer to them in various web forms. Though this approach works, it's not the best approach to make use of such client side libraries. That is where Content Delivery Network or CDN comes into picture. As an ASP.NET developer it would be nice to know what a CDN is and how Microsoft Ajax CDN can be used in ASP.NET web sites to refer ASP.NET AJAX and jQuery files. The remainder of the article discusses these concepts.

  • Developing a Database Driven Accordion Menu Using WCF and jQuery

    Web sites often use menus to display available options to the end user. The data required by these menus, such as menu text and URL, is frequently stored in XML files. Though this arrangement works great for small number of menu items, in certain applications it is required that you display menu options based on the security credentials of the current user. At times you may also need to display menus in Unicode character set. In such cases storing menu data in a database table can be more beneficial than maintaining separate XML files. In this article you will develop an Accordion menu that fetches data such as menu text, menu items and URL from a database table. An Accordion menu essentially displays menu options in collapsible panels. At a time only one menu and its options are expanded while other menus are collapsed. In order to develop our Accordion menu we will make use of ASP.NET, Windows Communication Foundation (WCF) and jQuery.

  • Book Review : ASP.NET MVC 2 Cookbook

    When you start learning new technology, one way is to follow start-to-end kind of approach where step by step you build your skills from basic to advanced concepts. The other approach, which is often fast and efficient, is to learn by working examples. ASP.NET MVC 2 Cookbook by Packt Publishing follows such an approach. The book presents over 70 code recipes in ASP.NET MVC to make you up and running with MVC 2 quickly. Note, however, that book doesn't delve too much on the theory of MVC. It focuses on practical implementation of MVC with the help of small small examples.

  • Creating and Using a jQuery Plug-in in ASP.NET Web Forms

    Developers often resort to code reuse techniques in their projects. As far as ASP.NET framework server side programming is concerned classes, class libraries, components, custom server controls and user controls are popular code reuse techniques. Modern ASP.NET web applications no longer restrict themselves only to server side programming. They also make use of client side scripting to render rich web forms. No wonder that Microsoft Visual Studio 2010 includes jQuery library by default as a part of newly created web site. If you are using jQuery for client side scripting then one way to reuse your client side code is to create a jQuery plug-in. Creating a plug-in allows you to bundle your reusable jQuery code in a neat way and then reuse it across web forms. In this article you will learn how to create a simple jQuery plug-in from scratch. You will also learn about certain guidelines that help you build professional jQuery plug-ins.

  • Book Review : ASP.NET Site Performance Secrets

    Any web site developer sooner or later encounters a situation where he or the client is not so happy with the performance of the web site under consideration. No wonder experienced developers look for opportunities to squeeze last drop of performance from their web sites. To that end, ASP.NET Site Performance Secrets provides sound understand of the time proven techniques of performance optimization.

  • Using GridView and DetailsView in ASP.NET MVC - Part 1

    For any beginner in ASP.NET MVC the first disappointment is possibly the lack of any server controls. ASP.NET MVC divides the entire processing logic into three distinct parts namely model, view and controller. In the process views (that represent UI under MVC architecture) need to sacrifice three important features of web forms viz. Postbacks, ViewState and rich event model. Though server controls are not a recommended choice under ASP.NET MVC there are situations where you may need to use server controls. In this two part article I am going to explain, as an example, how GridView and DetailsView can be used in ASP.NET MVC without breaking the MVC pattern.

  • Creating ASP.NET MVC "Web Site"

    If you used ASP.NET MVC before, you are probably aware that Visual Studio provides ASP.NET MVC Web Application project template to create MVC based applications. There is no option to create MVC Web Sites. In this article I am going to explain how I solved this issue in one of my application.

  • Consuming ASMX and WCF Services using jQuery

    In the previous part I demonstrated how jQuery animations can add some jazz to your web forms. Now let's see one of the most important feature of jQuery that you will probably use in all data driven websites - accessing server data. In the previous articles you used jQuery methods such as $.get() to make a GET request to the server. More powerful feature, however, is to make AJAX calls to ASP.NET Web Services, Page Methods and WCF services. The $.ajax() method of jQuery allows you to access these services. In fact $.get() method you used earlier internally makes use of $.ajax() method but restricts itself only to GET requests. The $.ajax() method provides more control on how the services are called.