Anup Shah on WPF and Silverlight (Programming Garden)

IT 's For You!!!

Monday, December 31, 2012

Difference between Truncate and Delete

i) Truncate an Delete both are used to delete data from the table.
ii) These both the command will only delete the data of the specified table, they cannot remove the whole table data along with its structure both the SQL statements are used to only delete the data from the table but they both differ from each other in many aspects like syntax, performance, resources uses etc.
So, first let’s take a look of both of these terms (Truncate and Delete),

-> Truncate command in SQL removes all rows from a table without logging the individual row deletion in the transaction log.
-> Truncate statement having the sane functionality as the Delete command has that is it deletes the data from the table without modifying or deleting the structure of the table.
-> You can not use the Where Clause with this (Truncate) statement.

TRUNCATE TABLE [ { database_name.[ schema_name ]. | schema_name . } ] table_name Table_name : Is the name of the table to truncate or from which all rows are removed.
Simple it looks like below query.
The above command will delete all data from the table Employees.

-> Delete command in SQL also removes all rows from a table with logging the individual row deletion in the transaction log.
-> You can use the Where Clause with this (Delete) statement.
-> For more focus please follow the link Click me

DELETE FROM TABLE_NAME[ { database_name.[ schema_name ]. | schema_name . } ] table_name Table_name : Is the name of the table to truncate or from which all rows are removed.
Simple it looks like below query.
The above command will delete all data from the table Employees.
In case of delete statements you can limit your delete query using where clause to delete, only particular records that fulfills the condition of where clause will be deleted not the all records.
It looks like below query with where clause.
DELETE FROM Employees Where EmployeeID IN (1,2,3)

Happy Coding!!! 

Thursday, December 13, 2012

SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server.

These are the common questions, How to import CSV file into SQL Server? How to load CSV file into SQL Server Database Table? How to load comma delimited file into SQL Server? 
Let us see the solution here
CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values.

1) Create a Table using the below script: (To Download Please Click Here)

USE [Experimental]
/****** Object:  Table [dbo].[CSVTest]    Script Date: 12/13/2012 16:08:02 ******/
[ID] [int] NOT NULL,
[FirstName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LastName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BirthDate] [smalldatetime] NULL


2) Create CSV file in drive e: with name csvtest.txt with following content. The location of the file is E:\csvtest.txt (To Download Please Click Here)
1, Anup, Shah, 19880803
2, Mac, Macwan, 19880803
3, Ankit, Patel, 19880803
4, Devang, Shah, 19880803

3) Now run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted. 
INSERT CSVTestFROM 'E:\csvtest.txt' WITH

--Check the content of the table.

Converting SQL Server Database to XML format

i. First Open Notepad and write below code till </root>:


Now Save it as c:\sqlexamples\template.tpl

Next you open SQL Server Query Editor and type:

sp_makewebtask @outputfile = 'c:\myxmlfile.xml',
    @query = 'select * from sysobjects for xml auto',
    @templatefile = 'c:\sqlexamples\template.tpl'

The Result is a XML-File!

Happy Coding! ;)

Wednesday, November 21, 2012

What is the difference Function and Stored Procedure?

1. UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.

2. UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.

3. Inline UDF›s can be though of as views that take parameters and can be used in JOINs and other Rowset operations.

A fire argues?

Thursday, November 8, 2012

Create ASPNETDB database using aspnet_regsql tool


Microsoft has introduced a powerful default database schema in ASP.Net 2.0 as ASPNETDB.mdf database. This database file serves as a role provider, membership provider and web parts personalization handling with the help of BLOBs.

Microso Visual Studio supports the ASP.Net configuration to manage this personal ASPNETDB database file within the web application inside the App_Data folder.

Uses of ASPNETDB database: 

ASPNETDB database helps in managing users along with their roles e.g. admin, employee, editors, etc.
It also enables the in-built functionality of Login controls and web parts to be integrated on ASP.Net web pages that helps in managing user profiles, login, and personalized user pages very easily even without writing the bulky code to implement the SQL queries or stored procedures along with data access code for inserting, updating or deleting the user personalized data.

How to use ASPNETDB database?

Fist you need to merge ASPNETDB with your own database. You can merge both databases using tool called "aspnet_regsql".

You can use aspnet_regsql command to create ASPNETDB database. This command executes the default scripts to create the default database for ASP.Net web applications.

Steps to create ASPNETDB database using aspnet_regsql tool:  

Open the Visual Studio command prompt from Start -> All Programs -> Microsoft Visual Studio 2005 -> Visual Studio Tools -> Visual Studio 2005 Command Prompt
Type aspnet_regsql and press enter key. This will open the ASP.Net SQL Server Setup Wizard. Click next to continue…
In the next dialog box, select the option "Configure SQL Server for application services". This option executes a script to configure the database for managing user profiles, roles, membership and personalization. Click next to continue…
In this step enter the SQL server name and choose the right authentication method. Leave the database field to default and click next…
Confirm your settings and click next to finish


 1. Open the command line by opening the Run dialog box and enter cmd. Then change to the directory C:\Windows\Microsoft.NET\Framework\v2.0.50727
[Note that the last directory’s name may be different, just make sure it’s v2.0, which signifies version 2.0 of the .NET Framework]
 2.  In this directory run the executable called aspnet_regsql.exe
 3. Follow the wizard provide Server Name and the Database Finish it.


Go Through my post simple way.

To let the solution use the database for user access and profiles, a hidden connection string called LocalSqlServer has to be removed and added again with the new settings. The following code example does that.

        <!-- Previously defined connection strings will be here -->      
        <!-- LocalSqlServer is the connectionstring used by the -->
        <!-- access and profile modules -->
        <remove name="LocalSqlServer"></remove>
        <add name="LocalSqlServer"
            connectionString="Data Source=anupDB2005;
                              Initial Catalog=ExperimentalDB;
                              User ID=anup;

Once you merge both databases using above steps, you need to upload them in live server.

Happy Coding...:)
Hope it can be helpful for you!

Thanks & Regards,
, , ,

How to create Aspnetdb database

1- Create your database in SQL server.
2- Open up your ASP.NET website in which you'd like to use ASP.NET membership features.

//Library Used
using System.Web.Management;

//This is the Code which you have to put on a web site which you are working on or any else...put it on page load event.

System.Web.Management.SqlServices.Install("YOUR_SERVER", "YOUR_DATABASE", SqlFeatures.All);

YOUR_SERVER - Means your SQL server name
YOUR_DATABASE- Means your Database in which you want to have this functionality

after execution please go to database and check it the table will be created.
, ,

Wednesday, October 24, 2012

State Management in Silverlight using Isolation Storage Help

            In ASP.Net, Silverlight has no concept of a session. To store session information we have to store the data in isolation storage. Suppose after login you have to display your log in name through several pages. SO the best way to store the data for displaying it is isolation storage and then you can retrieve it later.

            Now in this example below I will enter a user name and when I press submit it will store it in the isolation storage and also display it in the label by getting the value from the isolation storage.

            Create a new Silver light Application name "isolationwrittingfile".

            Now in the page.xaml paste the code below:<UserControl x:Class="isolationwritting_file.MainPage"    xmlns=""    xmlns:x=""    xmlns:d=""    xmlns:mc=""    mc:Ignorable="d"    d:DesignHeight="300" d:DesignWidth="400"xmlns:sdk="">
    <Grid x:Name="LayoutRoot" Background="White">        <TextBox Height="23" HorizontalAlignment="Left" Margin="152,37,0,0" Name="textBox1"VerticalAlignment="Top" Width="120" Text="" />        <sdk:Label Height="28" HorizontalAlignment="Left" Margin="26,37,0,0" Name="label1"VerticalAlignment="Top" Width="120" Content="UserName" />        <sdk:Label Height="28" HorizontalAlignment="Left" Margin="26,105,0,0" Name="label2"VerticalAlignment="Top" Width="120" />        <Button Content="Submit" Height="23" HorizontalAlignment="Left" Margin="278,37,0,0"Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />    </Grid>
It will look like Figure 1:


Now in the Page.xaml.cs paste the code below:using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.IO.IsolatedStorage;using System.IO;
namespace isolationwritting_file
    public partial class MainPage : UserControl    {
        public MainPage()
            //SaveData("Hello There", "MyData.txt");             //string test = LoadData("MyData.txt");            //textBox1.Text = test.ToString();        }
        private void SaveData(string data, string fileName)
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName,FileMode.Create, isf))
                    using (StreamWriter sw = new StreamWriter(isfs)) 
                    { sw.Write(data); sw.Close(); }
        private string LoadData(string fileName)
        { string data = String.Empty;
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) 
                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName,FileMode.Open, isf))
                    using (StreamReader sr = new StreamReader(isfs)) 
                        string lineOfData = String.Empty; 
                        while ((lineOfData = sr.ReadLine()) != null)   
                            data += lineOfData; 
            return data;
        private void button1_Click(object sender, RoutedEventArgs e)
            SaveData(textBox1 .Text , "MyData.txt");
            string test = LoadData("MyData.txt");
            label2.Content = "Your UserName is" + test.ToString();

In the SaveData method under the button click I am passing the "textBox1 .Text" parameter and also the ""MyData.txt" file name which will be created in the isolation storage.

The Method "LoadData()" retrieves the value from the isolation storage.

Now run the program; it will look like Figure 2:


Figure 2:

When you enter the user name and press submit button it will look like Figure 3:


Figure 3:

Conclusion: So in this article we have learned about using isolation storage for maintaining the state management in Silverlight.

Tuesday, October 23, 2012

What is the difference between transaction and query?

A query is a single SQL statement that does Select, Update, Insert or Delete of rows.

A transaction is a consecutive sequence of SQL statements (from the application viewpoint) that have the "ACID" properties:
  • Atomicity: All statements or none are executed.
  • Consistency: Data integrity is always maintained.
  • Isolation: Transaction A can never affect Transaction B.
  • Durability: Changes that are committed by a transaction persist, even in event of system failure.

Understanding Basics of UI Design Pattern MVC, MVP and MVVM


This is my first article and I hope you will like it. After reading this article, you will have a good understanding about "Why we need UI design pattern for our application?" and "What are basic differences between different UI patterns (MVC, MVP, MVVP)?”.
In traditional UI development - developer used to create a View using window or usercontrol or page and then write all logical code (Event handling, initialization and data model, etc.) in code behind and hence they were basically making code as a part of view definition class itself. This approach increased the size of my view class and created a very strong dependency between my UI and data binding logic and business operations. In this situation, no two developers can work simultaneously on the same view and also one developer's changes might break the other code. So everything is in one place is always a bad idea for maintainability, extendibility and testability prospective. So if you look at the big picture, you can feel that all these problems exist because there is a very tight coupling between the following items.
  1. View (UI)
  2. Model (Data displayed in UI)
  3. Glue code (Event handling, binding, business logic)
Definition of Glue code is different in each pattern. Although view and model is used with the same definition in all patterns.
In case of MVC it is controller. In case of MVP it is presenter. In case of MVVM it is view model.
If you look at the first two characters in all the above patterns, it remain same i.e. stands for model and view. All these patterns are different but have a common objective that is “Separation of Duties"
In order to understand the entire article, I request readers to first understand the above entity. A fair idea about these will help you to understand this article. If you ever worked on UI module, you can easily relate these entities with your application.
MVC (model view controller), MVP (model view presenter) and MVVM (model view view model) patterns allow us to develop applications with loss coupling and separation of concern which in turn improve testability, maintainability and extendibility with minimum effort.
MVVM pattern is a one of the best solutions to handle such problems for WPF and Silverlight application. During this article, I will compare MVC, MVP and MVVM at the definition level.


Before we dig into MVVM, let’s start with some history: There were already many popular design patterns available to make UI development easy and fast. For example, MVP (model view presenter) pattern is one of the very popular patterns among other design patterns available in the market. MVP is a variation of MVC pattern which is being used for so many decades. Simple definition of MVP is that it contains three components: Model, View and presenter. So view is nothing but a UI which displays on the screen for user, the data it displays is the model, and the Presenter hooks the two together (View and model).
The view relies on a Presenter to populate it with model data, react to user input, and provide input validation. For example, if user clicks on save button, corresponding handling is not in code behind, it’s now in presenter. If you wanted to study it in detail, here is the MSDN link.
In the MVC, the Controller is responsible for determining which View is displayed in response to any action including when the application loads. This differs from MVP where actions route through the View to the Presenter. In MVC, every action in the View basically calls to a Controller along with an action. In web application, each action is a call to a URL and for each such call there is a controller available in the application who respond to such call. Once that Controller has completed its processing, it will return the correct View.
In case of MVP, view binds to the Model directly through data binding. In this case, it's the Presenter's job to pass off the Model to the View so that it can bind to it. The Presenter will also contain logic for gestures like pressing a button, navigation. It means while implementing this pattern, we have to write some code in code behind of view in order delegate (register) to the presenter. However, in case of MVC, a view does not directly bind to the Model. The view simply renders, and is completely stateless. In implementations of MVC, the View usually will not have any logic in the code behind. Since controller itself returns view while responding to URL action, there is no need to write any code in view code behind file.

MVC Steps

Step 1: Incoming request directed to Controller.
Step 2Controller processes request and forms a data Model.
Step 3Model is passed to View.
Step 4View transforms Model into appropriate output format.
Step 5: Response is rendered.
So now you have basic understanding of MVC and MVP. Let’s move to MVVM.

MVVM (Model View ViewModel)

The MVVM pattern includes three key parts:
  1. Model (Business rule, data access, model classes)
  2. View (User interface (XAML))
  3. ViewModel (Agent or middle man between view and model)
Model and View work just like MVC and “ViewModel” is the model of the View.
  • ViewModel acts as an interface between model and View.
  • ViewModel provides data binding between View and model data.
  • ViewModel handles all UI actions by using command.
In MVVM, ViewModel does not need a reference to a view. The view binds its control value to properties on a ViewModel, which, in turn, exposes data contained in model objects. In simple words, TextBox text property is bound with name property in ViewModel.
In View:
<TextBlock Text="{Binding Name}"/> 
In ViewModel:
public string Name
       = value;
ViewModel reference is set to a DataContext of View in order to set view data binding (glue between view and ViewModel model).
Code behind code of View:
public IViewModel Model
                return this.DataContext as IViewModel;
                this.DataContext = value;
If property values in the ViewModel change, those new values automatically propagate to the view via data binding and via notification. When the user performs some action in the view for example clicking on save button, a command on theViewModel executes to perform the requested action. In this process, it’s the ViewModel which modifies model data, View never modifies it. The view classes have no idea that the model classes exist, while the ViewModel and model are unaware of the view. In fact, the model doesn’t have any idea about ViewModel and view exists.

Where to Use What in the .NET World

  • Model-View-Controller (MVC) pattern
    • ASP.NET MVC 4 Link
    • Disconnected Web Based Applications
  • Model-View-Presenter (MVP) pattern
    • Web Forms/SharePoint, Windows Forms
  • Model-View-ViewModel (MVVM) pattern
    • Silverlight, WPF Link
    • Data binding

, ,

MVC Basics

The ASP.NET MVC Framework is a web application framework that implements the model-view-controller pattern. Based on ASP.NET, it allows software developers to build a Web application as a composition of three roles:

ModelView and Controller

model represents the state of a particular aspect of the application. Frequently, a model maps to a database table with the entries in the table representing the state of the application.

controllerhandles interactions and updates the model to reflect a change in state of the application, and then passes information to the view.

view accepts necessary information from the controller and renders a user interface to display that

View - just the UI (HTML), there's no much logic there only logic for taking data from the Model. View just take a Model and render it's content on the page. There's no code behind, no .aspx.vb or .aspx.cs

Model - contains all data that view needs to display

Controller - is the boss, the controller handling HTTP requests for web page and it's role is to create a model (read data from DB, bussiness logic etc) and selects proper view for render. Controller never interacts with the user interface, it's job of the View. And never holds any data or statements, it's job of the Model.

Folder structure of app:

  • "Controllers" folder is the place where the controllers are placed. The name convention is the controller name must end with "Controller" word, for eg.: HomeController -> Home is the name of the controller. And "Controller" is required postfix. In the code you using just a name (for eg. Home) but controller classes needs the have there the Controller postfix to be properly handled by MVC engine.
  • "Views" is the place for views.
    When the view represents action result (for eg. aspx page) then view name needs to match with action names used for.
    When view is usercontrol you can name it whatever you what.Under Views folder you will have list of folders with controller names and the one called Shared. The folders with the controller names are there just because the view is somehow associated with the controller. Another words when the controller return views that's the place where the MVC is looking for particular view that needs to be renders. The "Shared" folder is the place for user controls, master pages etc. The "Shared" folder contains views used by multiple controllers.
  • "Models" - place for object definitions that will be populated with the Controller and used by View for rendering.

Tuesday, July 24, 2012

Silverlight vs. HTML 5

Most of the Silverlight Details are from this Silverlight Blog Post

Can be programmed with a statically-typed .net language like C#, which is compiled and a lot of errors can be caught at compile time.
Requires extensive javascript coding to extract maximum functionality, which is not compiled and errors are prone, requiring extensive testing. Also requires extensive CSS/CSS3 knowledge and usage.
Silverlight is a plugin works the same in IE and all other browsers.
HTML5 is a work in progress, the standards body scheduled to complete specs in 2022, could work differently in different browsers. Also it might require using the DOM elements supported by the different browsers. Requires understanding of the browser sensibilities to the DOM elements, since all browsers are not standards compliant, especially IE.
UPDATE on 02/14/2011: HTML5 Spec to be completed in 2014, check this updated article
With newer versions of Silverlight released, newer browser versions should support the older versions of silverlight. If we build in Silverlight 4.0 and the application is running fine. If a newer version of a browser is released which will not support Silverlight 4.0( instead it supports a newer version of Silverlight), we may have to stop the users from upgrading to a newer version of browser.
HTML5 as it is now, is not supported in older versions of the browser like IE6 and IE7. HTML5 is also evolving and newer browser versions will have better support for HTML5, but it may work differently in different browsers, since there is no defined HTML5 standard as yet and it is a work in progress. But for the most part, HTML5 once built should work in newer versions of the browser.
Silverlight requires a plugin required to be installed in the browser, as of now it is not bundled into the browser. Some systems might not allow to install plugins.
HTML5 is built into the newer versions of the browser, no plugin required.
Easier to program complex and rich functionality with a known language like C#
Javascript is evolving faster, there are rich libraries like jQuery which provide rich functionality but not equivalent to Silverlight.
Silverlight video plays as long as the silverlight plugin is installed in the broswer. Will not work on Apple devices like iPad and iPhone.
Depending on the encoding, if the video is encoded in H.264, HTML5 will play the video in IE and Safari without installing any additional plugin. Also works on Apple devices like iPad and iPhone. Firefox, Chrome and Opera support Theora or Vorbis encoding, with support for WebM soon. Requires the video to be encoded in more than one codec to support all browsers.
Silverlight on smartphones is a disadvantage since it is resource hungry and not supported on all platforms.
HTML5 is lightweight comparatively since it is built into the browser and it does not take up as much resources.
Silverlight application performance will be better since it is already parsed and compiled into bytecode form.
Javascript performance is increasing rapidly with better javascript engines in the newer browsers, but since it is dynamically typed language it might not be the same as the statically-typed and compiled silverlight.
Intellectual Property Protection is better with Silverlight, since it is not easy to reverse engineer a silverlight application.
There is no easy way to obfuscate HTML and Javascript, so competitors can easily view the source.
Webkit layout engine based smartphone browsers like Safari, Chrome and Opera do not support Silverlight. Webkit is evolving fast as the mobile browser standard.
HTML5, Javascript and Css work well on Webkit based browsers. Webkit javascript core called SquirrelFish compiles JavaScript into native machine code, eliminating the need for a bytecode interpreter and thus speeding up Javascript execution.
Client side local storage using IsolatedStorage, upto 1MB, can be increased with permissions. Need to store in files and read from files. Data stored in the local storage can be encrypted for security.
HTML5 supports SQLLite, a lightweight client side database, can be saved and retrived as queries. Can store upto 5MB, not supported on all browsers. Currently only Safari, Chrome and Opera. Not supported in IE yet. Local storage data cannot be encrypted like Silverlight storage.
Silverlight can access the Webcam/Microphone on the users desktop, providing richer media experiences.
HTML5 does not support access to the WebCam/Microphone as of yet.
Silverlight videos content can be protected through DRM( Digital Rights Management).
HTML5 videos do not support DRM
Silverlight supports adaptive smooth streaming, Silverlight videos are encoded into 3 definitions, depending on the bandwidth availability, it will stream the appropriate quality, like the highest quality for the most bandwidth and the lowest quality for the least bandwidth.
No such support in HTML5
Silverlight media supports Information Overlay/Picture in Picture.
Not supported by default.
Great Stereoscopic 3D video support out of the box.
Supports 3D, but not as good as Silverlight.
Ability to broadcast live( video/audio) or streaming.
Not supported at this time.
Comes with a full set of 60+ pre-built controls with customizable styles, also with several third party enhanced control libraries available.
Need to work with available open source javascript plugins, or can build functionality using Javascript, HTML5 and CSS/CSS3. To get some of the functionality of advanced Silverlight controls, requires a lot of scripting work.
Powerful data visualization through charting controls and Silverlight Pivotviewer.
Plugins and libraries are available, but are not as rich as the Silverlight controls.
Flexible data support including databinding, binary XML, LINQ and local storage.
There is no 2-way databinding support, as well as support for LINQ.  HTML5 does support 2 flavors of local storage including SQLLite.
Provides Multicasting support, but it works on the UDP protocol, which has a limitation since it is blocked by most common firewalls. Also packet security needs to be built by the user since the packet delivered cannot be guaranteed to be the same as the packet sent. But great for interactive web applications.
No multicasting support yet.
Responsive UI with .net and Multithreading.
Can provide somewhat seamless experience through AJAX, but may not be the same as Silverlight.
Conflicting recent views from Microsoft about the future of Silverlight, creating some doubts in the minds of developers. Some confusion about MS going to keep improving on Silverlight or put more efforts into better HTM5 standards support.
HTML5 is evolving, so no way to know if there are going to be a lot of changes or even if it requires tweaking code with future versions.
Silverlight works on most browsers and versions.
HTML5 is partially supported in Safari, Chrome and Firefox. IE still does not support HTML5
Newer desktops, laptops, smartphones and tablets are coming with 2 or more processor cores. Silverlight on .net framework is capable of scaling upto 8 processor cores.
Javascript does not support true parallelism, it may come in the future, but not right now.
Silverlight provides rich functionality out of the box or third party control libraries, easy to upgrade an existing application with newer versions of the controls, since most controls are built with backward compatibility, can be upgraded easily by just referencing newer dlls.
To get all the functionality of the Silverlight controls, need more than one javascript framework, library or plugin. All of them are not fully tested, so need to upgrade several code sources to keep up with the upgrades. Also all upgrades might not have proper backward compatibility.
Silverlight can be written once and deployed to the web/desktop. ( Unfortunately cannot be deployed on Windows Phone 7 since it uses a different set of lightweight controls)
HTML5 is a markup language for the web. It needs a web browser to render itself.
Silverlight multi-touch support can take advantage of the next-generation hardware natively.
Depends on the multi-touch support of the browser.
Silverlight can offload media rendering to the GPU  for Hardware Acceleration. More than one control which supports Hardware Acceleration, 3D and Pixel shaders.
No Hardware Acceleration support as of yet. Plans to support it in the future using WebGL technology for the HTML Canvas. WebGL will bring Hardware Acceleration, 3D and pixel shaders.
Current web is built on the request/response architecture. A user makes a request for a page to the server, the server sends back the page to the client. After that the page remains static. With Silverlight, if there is a change in the content in the server, it can be easily reflected in the client with the Publisher/Subscriber architecture using net.tcp or WCF duplex pooling.
Not so easy and elegant to do with AJAX and javascript, requires lot more coding and also performance is slower.
Faster development with better IDE, tools and controls. Also use existing developer language strengths.
Development tools are evolving for javascript, HTML and CSS.
Silverlight content is not indexed by the Search Engines, not good for Search Engine Optimization.
HTML is Search Engine friendly, with HTML5 more semantic capabilities are being added for providing better content to the Search Engines.