Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for the ‘.Net’ Category

Visual Studio LightSwitch

Microsoft Visual Studio LightSwitch helps you solve specific business needs by enabling you to quickly create professional-quality business applications, regardless of your development skills. LightSwitch is a new addition to the Visual Studio family. Visual Studio LightSwitch is designed to simplify and shorten the development of typical forms-over-data business applications.

Scenario: forms-over-data business
Advantages:

  •  simplify and shorten the development
  •  you do not need to know .net and etc.

The build-in starter kit
Customer Service
Application for managing customer accounts and invoices.

Expense Tracker
Application for creating and tracking expense reports.

Issue Tracker
Application for tracking issues logged to an IT helpdesk.

Job Candidate Tracker
Application for managing job applicants and open positions.

Performance Review
Application for tracking employee performance data.

Status Report
Application for tracking project updates and other statuses.

Time Tracker
Application for managing employee time entry.

Call web service via jQuery in asp.net

step 1. Add Web service, and you must add a [System.Web.Script.Services.ScriptService] to the service class

(in webservice.asmx.cs file)

   1: /// <summary>

   2: /// Summary description for WebService1

   3: /// </summary>

   4: [WebService(Namespace = "http://tempuri.org/")]

   5: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

   6: [System.ComponentModel.ToolboxItem(false)]

   7: // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 

   8: [System.Web.Script.Services.ScriptService]

   9: public class WebService1 : System.Web.Services.WebService

  10: {

  11:     [WebMethod]

  12:     public string DeleteProduct(string id)

  13:     {

  14:         Thread.Sleep(800);

  15:         return "Hello World22: " + id;

  16:     }

  17: }

step 2. call webservice in aspx via jQuery

(in head of the page)

   1: <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

   2: <script type="text/javascript">

   3:     $(function () {

   4:         $('a').click(function () {

   5:             deleteProduct(111);

   6:         }); // end of  $('a').click(function () {

   7:  

   8:     });     // end of $(function () {

   9:  

  10:  

  11:  

  12:     function deleteProduct(id) {

  13:         $.ajax({

  14:             type: "POST",

  15:             url: "WebService1.asmx/DeleteProduct",

  16:             data: "{id: '" + id.toString() + "'}",

  17:             contentType: "application/json; charset=utf-8",

  18:             dataType: "json",

  19:             success: function (msg) {

  20:                 AjaxSucceeded(msg);

  21:             },

  22:             error: AjaxFailed

  23:         });

  24:     }

  25:     function AjaxSucceeded(result) {

  26:         alert(result.d);

  27:     }

  28:     function AjaxFailed(result) {

  29:         alert(result.status + ' - ' + result.statusText);

  30:     }  

  31: </script>

Web Essentials extension – Visual Studio 2010 add-on

The Web Essentials extension lets you perform common tasks much easier,

Features include:

  • Minify CSS
  • Same word highlighting
  • Code collapsing/outlining
  • Convert easily between hex, rgb and named color values
  • Right-click folder now includes Add JavaScript and Stylesheets
  • Adds SmartTags to selectors for targeting specific IE versions
  • Color preview on mouse hover
  • Font preview on mouse hover
  • Image preview on mouse hover
  • Support for regions /*#region MyRegion */
  • Brace matching
  • Minify JavaScript
  • Adds SmartTags to properties for targeting IE6 & IE7
  • Embed url() references as base64 strings
  • Drag and drop support for image, font, audio and video files

Download at http://visualstudiogallery.msdn.microsoft.com/6ed4c78f-a23e-49ad-b5fd-369af0c2107f

Use HttpRuntime.Cache to call asp.net Cache

In some scenario, you can’t visit asp.net cache, even via HttpContext.Current.Cache. For example, in Unit Test mode. In this case, you can use the HttpRuntime.Cache to access asp.net Cache.

Entity Framework Code First

The “EF Code-First” functionality provides a pretty nice code-centric way to work with data.

Advantage

  • ·         Develop without ever having to open a designer or define an XML mapping file, and start from a class
  • ·         Define your model objects by simply writing “plain old classes” with no base classes required
  • ·         Use a “convention over configuration” approach that enables database persistence without explicitly configuring anything
  • ·         Optionally override the convention-based persistence and use a fluent code API to fully customize the persistence mapping. columbus oh website design

Disadvantage

  • Mapping entities to the database is quite complex
  • There is no Model diagram

Update the ViewModel when a Text is changed in the View (WPF-MVMV)

There are 4 types of UpdateSourceTrigger types in binding, they are

Default: The default UpdateSourceTrigger value of the binding target property. The default value for most dependency properties is PropertyChanged, while the Text property has a default value of LostFocus. A programmatic way to determine the default UpdateSourceTrigger value of a dependency property is to get the property metadata of the property using GetMetadata and then check the value of the DefaultUpdateSourceTrigger property.

PropertyChanged: Updates the binding source immediately whenever the binding target property changes.

LostFocus: Updates the binding source whenever the binding target element loses focus.

Explicit: Updates the binding source only when you call the UpdateSource method.

So, use the PropertyChanged binding type can update the VM immediate when a text is change, for example

<TextBox Text="{Binding UserAlias, UpdateSourceTrigger=PropertyChanged}" />