Posts

LINQ to SQL

Image
LINQ to SQL allows .NET developers to write “queries” in their .NET language of choice to retrieve and manipulate data from a SQL Server database. In a general sense, LINQ to SQL allows us to create SQL queries in our preferred .NET language syntax and work with a strongly types collection of objects as a return result. We can make changes to these objects then save changes back to the database. To get an idea of the syntax for LINQ to SQL, we will be using the following SQL database schema. It is a simple software registration and helpdesk. It is populated with sample data and has foreign-key relationships defined where appropriate. SQL Database Schema used for LINQ to SQL examples. For the moment I ask you to ignore the fact that we will be coding against a type HookedOnLINQ, I’ll get to how that was created in a few pages time, for now just understand it is an object structure that mimics this database schema. HookedOnLINQ db = new HookedOnLINQ ( "D...

Passing Data in an ASP.NET MVC Application

The ASP.NET MVC framework provides page-level containers that can pass data between controllers and views. This topic  explains how to pass both weakly typed and strongly typed data in an MVC application. It also explains how to pass  temporary state data between action methods Passing Data Between a Controller and a View To render a view, you call the View method of the controller. To pass data to the view, you use the ViewData property of  the ViewPage class. This property returns aViewDataDictionary object that has case-insensitive string keys. To pass data to  the view, you can assign values to the dictionary, as shown in the following example: List<string> petList = new List<string>(); petList.Add("Dog"); petList.Add("Cat"); petList.Add("Hamster"); petList.Add("Parrot"); petList.Add("Gold fish"); petList.Add("Mountain lion"); petList.Add("Elephant"); ViewData["Pets...

ASP.NET MVC Overview

Image
Introduction ASP.NET MVC is one of the methods of developing ASP.NET applications. In this article, we will go through the overview of ASP.NET MVC by creating a simple application. ASP.NET MVC Framework is Microsoft’s Web Application development framework, the other one being traditional webforms framework. MVC or Model View Controller is a design pattern that addresses the separation of concerns(Soc) which is the process of identifying and separating the application into distinct parts like UI, Logic and Data Access. Soc has proven to be useful in the design of web applications. Keeping the view separate from the other parts of the application means that we can easily change the view without affecting the rest of the application. Similarly, if we want to change the main application logic, we just need to change the controller. ASP.NET MVC is an implementation of the MVC design pattern. The framework helps Test Driven Development which is a method of development in which Unit Test Ca...

Implement a Cancel button while using Bindings, and send only an object's changes to a WCF service

Take the following scenario: A user of your application opens a customer for editing. They put in a new address. Now they realize they're in the wrong customer entirely and want to cancel their changes. What does your application do? If you're like me, then you are on a mission to keep code behind to an absolute minimum. You have two way bindings setup for everything. You're proud of all the C#/VB code that you  haven't  written in your application. So, your model is already updated. Do you not have a cancel button? Blame the user for the bad experience and tell them not to do that? Or did you add a reload method to your cancel button instead, forcing the application to grab data from a web service or a database? Another possible option might have been to follow MVVM completely and to separate the Model from the ViewModel even on the most basic classes. The ViewModel could then store copies of this data and include methods to move back to the object and to reload data ...

Send Cookies When Making WCF Service Calls

Image
Introduction This article presents an example on how to send cookies when making WCF service calls. Background Once in a while, you may find that you want to send some information in the form of " Cookies " to the server when making WCF calls. For example, if the WCF service is protected by a " Forms Authentication " mechanism, you will need to send the authentication cookie when making the WCF call to gain the required access to the service. If you are calling a " REST " service using the " WebClient " class, this should not be a difficult task. You can simply work on the " CookieContainer " property of the " HttpWebRequest " class. If you are calling a regular WCF service, and your client proxies are generated by the " Adding service reference " tool in the Visual Studio, the method to send cookies is not so obvious. This article is to present an example on how to send cookies when making WCF calls using the Vis...

ASP.net 4.0 Ajax

jQuery Included with Web Forms and MVC The Visual Studio templates for both Web Forms and MVC include the open-source jQuery library. When you create a new website or project, a Scripts folder containing the following 3 files is created: jQuery-1.4.1.js – The human-readable, unminified version of the jQuery library. jQuery-14.1.min.js – The minified version of the jQuery library. jQuery-1.4.1-vsdoc.js – The Intellisense documentation file for the jQuery library. Include the unminified version of jQuery while developing an application. Include the minified version of jQuery for production applications. For example, the following Web Forms page illustrates how you can use jQuery to change the background color of ASP.NET TextBox controls to yellow when they have focus. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowjQuery.aspx.cs" Inherits="ShowjQuery" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E...

ASP.net 4.0 Core Services

ASP.NET 4 introduces a number of features that improve core ASP.NET services such as output caching and session-state storage. Web.config File  Refactoring The  Web.config  file that contains the configuration for a Web application has grown considerably over the past few releases of the .NET Framework as new features have been added, such as Ajax, routing, and integration with IIS 7. This has made it harder to configure or start new Web applications without a tool like Visual Studio. In .the NET Framework 4, the major configuration elements have been moved to the  machine.config  file, and applications now inherit these settings. This allows the  Web.config  file in ASP.NET 4 applications either to be empty or to contain just the following lines, which specify for Visual Studio what version of the framework the application is targeting: <?xml version="1.0"?>   <configuration>    <system.web>   ...