Mike Borozdin's Blog

A blog about programming, web and IT in general

Search

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© 2008 Mike Borozdin

Recommended Advanced ASP.NET Books

I often see questions in the forums regarding ASP.NET books, usually people ask not only about reference style books, but about more advanced books that explain not only ASP.NET basics but teach you to write real world applications.

I know a really good book on that topic. This book focuses on building a web portal including news system, guest book, user registration, e-shop and many other features. Actually, this portal is a popular starter-kit called "E-commerce starter-kit" or "The Beer House" that you can find here.

The book is called "ASP.NET 2.0 Website Programming: Problem - Design - Solution".

The new edition that describes ASP.NET 3.5 including LINQ and ASP.NET AJAX will soon arrive.

So, the books are highly recommended by many professional ASP.NET developers.


Posted by Mike Borozdin on Thursday, July 31, 2008 8:36 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (0) | Post RSSRSS comment feed

Building Rich Internet Applications With ASP.NET AJAX Control Toolkit

Introduction

Nowadays web isn't a web as it was 10 years ago. Web isn't a collection of static pages anymore. Actually, there was JavaScript and DHTML, but still web sites were far behind desktop applications in terms of interactivity. After the invention of AJAX it became possible to build really interactive web applications that are nearly the same as desktop applications except they are run in a browser.

Writing AJAX JavaScript code is a pretty routine task, so it's sensible to use a library that already has the necessary functionality. While Visual Studio 2008 has built-in ASP.NET AJAX 1.0 library, it doesn't contain many useful things we need when we are writing rich Internet applications.

ASP.NET AJAX Control Toolkit

ASP.NET AJAX Control Toolkit or simply ACT is a thing that can help to write rich Internet applications. Basically, it's set a of useful interactive web controls that we usually find in desktop applications, but missing in web applications. These controls include sliders, pop-up calendars, modal dialogs and many others. We don't have to write any JavaScript code to use them in our applications, we just need to use ACT controls that are very similar to ordinary ASP.NET controls.

ACT is run both by Microsoft and community, so everybody can take part in the creation of the decent AJAX toolkit.

Installation

The installation isn't difficult, but still worth mentioning.

First, you need to download the kit, go to their CodePlex page and choose the appropriate package. After downloading unpack the contents of the archive somewhere. Open Visual Studio, expand Toolbox, right-click, choose "Add Tab", name it "AJAX Control Toolkit", then right-click again within the space of the newly created tab and select "Choose Items...", click "Browse", open the folder where you extracted the contents of the archive, open "SampleWebsite\Bin\AjaxControlToolkit.dll". The tab must become populated with the controls. If you drag any control to a web form, the necessary assemblies will be copied to the "Bin" folder of the web site and the ACT assembly will also got registered on the page.

Controls

ACT provides two types of controls:

  • Web controls
  • Extenders

Web controls are just ordinary ASP.NET controls with some enhanced client-side functionality

Extenders are controls built on top of the existing ASP.NET controls with an additional client-side functionality, for example, many controls, for instance Slider, use TextBox and store their value in it.

The full list of controls is:

An Example

Enough with the theory, let's do something practical, for example, let's try the Slider control.

Drag Slider from Toolbox onto your page.

Since, Slider is an extender and it extends TextBox, you should add a TextBox and add the TargetControlID attribute to the Slider:

<asp:TextBox ID="txtSlider" runat="server" />

<cc1:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="txtSlider" />

Don't forget to add ScriptManager to the page, because the page won't compile without it. You can compile it now and drag the slider. Unfortunately, it doesn't show the current value. You need to add a bound control, add Label next to the TextBox and set the BoundControlID of the SliderExtender:

<asp:TextBox ID="txtSlider" runat="server" />
<asp:Label ID="lblSlider" runat="server" />

<cc1:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="txtSlider" 
    BoundControlID="lblSlider" />

Now when sliding it you can see the value.

You can set the minimum value with the Mininum attribute, the maximum value with the Maximum attribue and the number of steps with the Steps attribute.

Conclusion

If you need to add some rich functionality to your web application, then you should consider using ASP.NET AJAX Control Toolkit that is still in its community sandbox, however as many projects that were marked as beta it can be shipped with the new versions of Visual Studio and become an integrated part of the further .NET Framework releases.

I recommend you to check this page where you can find all the examples and the documentation of every control available in the kit.


Posted by Mike Borozdin on Wednesday, July 30, 2008 10:26 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (1) | Post RSSRSS comment feed

Windows Live Writer Simplifies Your Blogging

Finally, I have installed Windows Live Writer and got amazed by its features. It does really simplify your blogging and save your time. With Live Writer you don't have to write a post in Word and then paste it to your blog, sometimes you even have to paste it to a another editor in order to get rid of Word text formatting. Now you don't have to do that.

Windows Live Writer supports many blogging platform, from Live Spaces to BlogEngine.NET and WordPress

Windows Live Writer has a built-in spell checker, so you don't need Word to check your spelling, it has nice formatting features, it supports different plug-in, so you can get a syntax highlighter, which is not available by default unfortunately. 

You can preview your posts, post preview is integrated into your blog design that looks awesome.

The only thing I didn't like is that it's not very obvious how to add new tags, because when your click the "TAG" button it only lists the existing tags, you can add new ones in the "Keywords field in the properties section.


Posted by Mike Borozdin on Sunday, July 27, 2008 3:54 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (2) | Post RSSRSS comment feed

Dzone Instead Of Digg

If you have a blog, then you want to promote it. It doesn’t matter whether you are motivated by money or by recognition.  It you release your writings to public, then you want people to read them. Nowadays one of the most popular promotion techniques is sending links to social bookmarking web sites. The most popular social bookmarking web site is Digg.com. But does Digg work perfectly for every blog? I mean, can you promote every blog with Digg?


The answer is no. Some blog posts can never reach the front page of Digg, not because they are bad, but because they don’t fit Digg, they don’t fit their audience. However, these posts can do well on Dzone. Dzone is real paradise for developers. If you have an excellent post on programming, then submit it to Dzone, you won’t get dissapointed. It was created by developers and for developers. I really love it. There are really interesting articles. The article describing some features of ASP.NET and PHP can hardly bring traffic from Digg, but they will bring you a lot of traffic, if you submit it to Dzone.


Am I obsessed about Dzone? May be ;-)! I didn’t always do well with it, but I was really happy to discover this web site, when someone submitted my store there.


Posted by Mike Borozdin on Thursday, July 24, 2008 9:36 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (3) | Post RSSRSS comment feed

Using Microsoft Synchronization Services For ADO.NET (Introducing Microsoft SQL Server Compact Edition (Part II))

In the previous part of the tutorial we learnt how to use SQL Server Compact Edition in our application. In this part we are going to learn how to synchronize the data between Compact Edition and a regular verson of SQL Server.


Visual Studio 2008 has built-in Synchronization Services that we’ll be using in our project.


Create a new Windows Forms Application. In Server Explorer create a new database; create a table with just two fields:

  • ID
  • SampleColumn

Then, go to Project->Add Component->Data->Local Database Cache

  Find the newly created database and choose the only table. Click ‘Ok’.  When it will ask you to create a DataSet, just click ‘Cancel’, we won’t use any datasets in this project. As you can see it adds to field to our table, one is responsible for the last created item and the other one for the last update item. Hopefully, it also provides the SQL scripts for undoing these changes.

It’s necessary to make the synchonization bi-directional, so that it allows us to syncrhonize in both directions. Unfortunately it cannot be done in the design mode, so we have to write some code. Right-click on the .sync file -> View Code, it will create a new file containing a partial class. Add this piece of code:

namespace SyncServices1 {
    public partial class LocalDataCache2SyncAgent {
        partial void OnInitialized(){
            SampleTable.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional; // if the table is called SampleTable
        }
    }
}

Then, let’s make a very simple form. Place two ListBoxes, one will be for the remote data and one for the local. Place a button as well that will trigger a syncrhonization process. Put also a textbox and a button that will be used for inserting data.

 


Now add some the code that will retrieve the data from the remote database and fill the approprate list, do the same for the local data.

using (SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=SyncServices1;Integrated Security=True;"))
{

    con.Open();
    SqlCommand comSelect = new SqlCommand("SELECT SampleColumn FROM SampleTable", con);


    SqlDataReader reader = comSelect.ExecuteReader();

    listServer.Items.Clear();
    while (reader.Read())
    {
        listServer.Items.Add(reader["SampleColumn"].ToString());
    }

    con.Close();
}

Then, go to the design view of the *.sync file, hit the ‘code’ button’ and copy the code. Add this code to the button OnClick event. It updates the databases only, so we have to add some code to update the view (form) of our application, the do to section hints at that.

private void btnSync_Click(object sender, EventArgs e)
{
    LocalDataCache2SyncAgent syncAgent = new LocalDataCache2SyncAgent();
    Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();

    FillServerList();
    FillLocalList();
}


So, let’s add some sample data to our remote server. Then, compile the project. See that the left box has the data, while the right one is empty, hit the ‘Sync’ button, and they will become synchonized.


Now, add some code that will handle inserting data in our local database.


Let’s add some text and click the ‘Sync’ button, so that the server will also get updated.

Conclususion

Microsoft Synchronization Services for ADO.NET is a great tool when you need to develop occasionally connected applications that require data synchronization. In the tutorial we saw how it's easy to peform such a synchronization.

Resources

Microsoft Sync Framework Developer Center

Microsoft Synchronization Services for ADO.NET Books Online

 


Posted by Mike Borozdin on Wednesday, July 23, 2008 12:20 AM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (1) | Post RSSRSS comment feed

Free SQL Server 2008 Hosting

Since I have already touched a topic of SQL Server, I want to inform that Discount ASP.NET has launched SQL 2008 Hosting Beta Program. If you are already a subscriber of Discount ASP.NET, you can activate it in your control panel, if not, then you can subscribe if you are looking for a good hosting provider.

Posted by Mike Borozdin on Monday, July 21, 2008 8:35 AM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (0) | Post RSSRSS comment feed

Introducing Microsoft SQL Server Compact Edition (Part I)

Microsoft SQL Server Compact Edition is an embeded database that allows you to integrate it in your destkop and mobile applications. It can be used in a variety of scenarios, just some examples:

  • a single-user application that still stores its data in the SQL database
  • a local cache of a remote SQL Server database,
  • a mobile application that synchronizes its local compact database with a remote database from time to time.
SQL Server Compact Edition takes about 1.5 MB on HDD and consumes about 5 MB of RAM. It’s free to use and free to distribute with your application.

The 3.5 version is shipped with Visual Studio 2008, however if you don’t have it, you can download it here.

In this part of the tutorial we will learn how to:
  • Create a desktop application that interacts with SQL Server CE by using stronly-typed datasets
  • Deploy a desktop application with emdeded SQL Server Compact Edition
  • Use SQL queries with SQL Server Compact Edition
  • Use LINQ with SQL Server Compact Edition

Desktop Application and DataSets

Create a new project, choose Windows Forms Application. Then go to Project -> Add Component and choose Local Database.



We will be prompted to create a DataSet, let’s do that.

Then find the newly created database in the Solution Explorer, it must be called Database1.sdf depending on the name you gave it, of course, double click on it, Server Explorer gets expanded, let’s create a table.





It looks exactly like if we were working with a regular SQL database.

Now to Data Sources, right-click on the only avaliable DataSet and choose Configure DataSet with Wizard



Add the only table. Then right-click on it, select Details and drag the Products table on the form.



You must get the form like this

 



Compile the project and test it. It works :-)!

 

Deployment

Ok, now we are going to make an installer for our project that will also include the data file and the files necessary for SQL Server Compact Edition.
Let’s add the setup wizard project to our solution. It is located it Other Project Types -> Setup and Deployment -> Setup Wizard

 



Then we select Setup for Windows application and Primary Output for our project. We should include the Database file – Datase1.sdf and the files necessary for running SQL Server Compact Edition. Open C:\Program Files\Microsoft SQL Server Compact Edition\3.5 and select all the DLLs.



Click Finish then. Build the application and the setup project and try to install it, it must be working.

SQL Queries
In the previous example we didn’t write a single line of code. But in real project we have to. Let’s see, how we canuse SQL with SQL Server Compact Edition. This time we are going to create a console application.
Create or include the previously created SDF database.
You have to add a reference to Compact Edition assembly that is called System.Data.SqlServerCe and of course you have to add the necessary namespace. Executing SQL queries with Compact Edition is no harder than doing the same with SQL Server, you just have to use the classed that have ‘Ce’ at the end.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;

namespace SqlCeConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlCeConnection con = new SqlCeConnection("Data Source=Db.sdf");
            con.Open();

            SqlCeCommand comInsert = new SqlCeCommand("INSERT INTO Products(Title, Category) VALUES('Ferrari F40', 'Sport cars')", con);
            comInsert.ExecuteNonQuery();

            SqlCeCommand comSelect = new SqlCeCommand("SELECT * FROM Products", con);
            SqlCeDataReader reader = comSelect.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine("{0} {1}", reader["Title"], reader["Category"]);
            }

            con.Close();
        }
    }
}

LINQ

You can use LINQ with SQL Server CE, as well, the main difference is that you cannot use the visual designer which generates an error when dragging CE tables, however you can use a command line utilily called SqlMetal, just type:


SqlMetal Database1.sdf /dbml:Database1.dbml


Then include the generated file in your project and Visual Studio will easly pick it up, then you can write LINQ queries as usual.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlServerCe;

namespace SqlCeConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Db db = new Db(@"Data source=Db.sdf");

            var result = from p in db.Products
                         select p;

            foreach (var product in result)
            {
                Console.WriteLine(product.Title);
            }
        }
    }
}

Next Part

In the next part of the tutorial I'll show how to synchronize the data between SQL Server Compact Edition and SQL Server.

Resources 

Official Microsoft SQL Server Compact Edition Homepage

Developer resources

Compact Edition Books Online

 


Posted by Mike Borozdin on Sunday, July 20, 2008 8:49 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (1) | Post RSSRSS comment feed

BlogEngine.NET: Making The Archive Work Without Categories

As you may notice I don’t use categories in my blog, only tags. Whether it’s good or bad – is a matter of another topic.  Now I’m going to talk about how to make the archive work properly if you don’t have any categories, because it doesn’t display any posts unless they are filed under some category. I hope this will be fixed in the next versions, but you can fix it yourself, it’s not difficult.


Open archive.aspx.cs, find the Page_Load() method and remove the line containing CreateMenu() that we don’t need, because this function just prints the list of the categories, but we don’t have any. Then, go to the CreateArchive() method. Can you see that it only returns the posts assigned to some category? That’s no good, just remove the foreach statement and change Post.GetPostsByCategory() to Post.Posts that will just return all the posts, no matter whether they belong to a particular category or not.

So, CreateArchive() should look like this:

private void CreateArchive()
{
  List<Post> list = Post.Posts;

  HtmlTable table = CreateTable("");

  foreach (Post post in list)
  {
            if (!post.IsVisible)
                continue;

    HtmlTableRow row = new HtmlTableRow();

    HtmlTableCell date = new HtmlTableCell();
    date.InnerHtml = post.DateCreated.ToString("yyyy-MM-dd");
    date.Attributes.Add("class", "date");
    row.Cells.Add(date);

    HtmlTableCell title = new HtmlTableCell();
    title.InnerHtml = string.Format("<a href=\"{0}\">{1}</a>", post.RelativeLink, post.Title);
    title.Attributes.Add("class", "title");
    row.Cells.Add(title);

    if (BlogSettings.Instance.IsCommentsEnabled)
    {
      HtmlTableCell comments = new HtmlTableCell();
      comments.InnerHtml = post.ApprovedComments.Count.ToString();
      comments.Attributes.Add("class", "comments");
      row.Cells.Add(comments);
    }

    if (BlogSettings.Instance.EnableRating)
    {
      HtmlTableCell rating = new HtmlTableCell();
      rating.InnerHtml = post.Raters == 0 ? "None" : Math.Round(post.Rating, 1).ToString();
      rating.Attributes.Add("class", "rating");
      row.Cells.Add(rating);
    }

    table.Rows.Add(row);
  }

  phArchive.Controls.Add(table);
}

archive.aspx.cs (4.62 kb)


Posted by Mike Borozdin on Friday, July 18, 2008 5:37 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (0) | Post RSSRSS comment feed

I'm Getting Back To Blogging

I have just returned from my great journey! It was marvelous! Besides Czech Republic and Germany I also visited Austria, its beautiful capital - Vienna, although I didn't plan that before.

Anyway, after a week break, I'm getting back to blogging.


Posted by Mike Borozdin on Sunday, July 13, 2008 3:58 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (0) | Post RSSRSS comment feed

I'm On Vacation

I’m on vacation for the next week, so I won’t post anything. I’ll be travelling to the centre of Europe – Czech Republic. I’ll be in Prague mosly, but will visit some other beautiful small towns, like Cesky Krumlov. I’ll also visit Germany for a day.


Yeah, I’m looking forward to going there :-)!


Posted by Mike Borozdin on Saturday, July 05, 2008 9:39 PM GMT
Bookmark on MSDN   Add to Technorati Favorites  Kick it!  
Permalink | Comments (1) | Post RSSRSS comment feed