Tuesday, June 3, 2008

Ajax .Net III : CalendarExtender Control

Ajax .Net Extender Controls are those controls that extend an Asp .Net Control by the way giving rich Ajax functionality.

Calendar Control extends Asp .Net so that the TextBox can be used for selecting date.
























Start A new website in Visual Studio 2008 or Ajax Enabled WebSite in Visual Studio 2005.
In the case of Visual Studio 2005 the Script Manager will available by default.
In Visual Studio 2008 you have to add a Script Manager.
Add a TextBox which you want to add Calendar support. Add CalendarExtender to the form.




















Set TargetControlId of CalendarExtender to TextBox1. Now when you run the application you will see a textbox as shown in the figure above.

It is that easy to enable date selection functionality to an textbox using CalendarExtender control.

Related Blog

Ajax .Net I : Extension Controls in Visual Studio 2008

Ajax .Net II : Setting up Ajax Control Toolkit controls

Ajax .Net III : CalendarExtender Control

Ajax .Net IV : TextBoxWaterMarkExtender

Ajax .Net VI : ConfirmButtonExtender

Monday, June 2, 2008

Asp .Net GridView Editing and Paging the Wizard way

GridView is an ASP .Net 2.0 control with inbuilt editing, paging and sorting support.
In this blog I am going to demonstrate enabling paging, sorting and editing in a no code way ie. using Wizard.


Place a GridView on Asp .Net Page. From the smart tag select Choose Data Source and New Data Source.

















Data Source Configuration Wizard wizard will appear. Select database and click Ok.




















From choose your data connection section of Wizard select New Connection



















The Add Connection dialog will appear.

























In the server name you can specify a . (dot) if you want to connect to Sql Server in the same machine, .\sqlserver if you want to connect to Sql Server 2005 or any machine name if you want to connect to Sql Server on another machine.

From select or enter a data base select the database you want to connect to.
Click on Test connection.

If everything is ok Test connection succeeded message will appear.

Your will be taken back to the wizard. Click Next



















Here if you want you can specify another name for the connectionstring which is an entry in web.config. Click Next.


Here you can specify the table of field. Make sure to check the advanced button.




















In the Advanced Sql Generation Option Dialog select Generate INSERT , UPDATE And Delete Statements and Use Optimistic concurrency. Click Next and click Test Query. Click on Finish.





















Now your grid is ready. Since we want to implement additional functionality, click on the smart tag and Select Enable Paging, Enable Sorting, Enable Editing and Enable Deleting.



















You have to set EnableSortingAndPagingCallbacks to true of Ajax enabling the GridView.

Lets explore what is happening behind the scene.
Asp .Net is adding a new entry inside connectionStrings in web.config.







An SqlDataSource control is added to the form which points to the connectionString:NorthwindConnectionString. It also contains code for insertion updation and deletion.















GridView's DataSource id is set to the SqlDataSouce control.










Happy Programming
Shalvin.com

This blog was posting in response to a request by Madhu. If you have any .Net doubts i will try to blog on that.
shalvin@gmail.com

Sunday, June 1, 2008

Silverlight.live.com : Excellent video quality

With silverlight.live.com one can upload videos and embed them in blog.
The video quality is excellent.

For this video to work you should have Silverlight installed in your machine. The movie will prompt you to download Silverlight. Silverlight is of 1.36 MB in size.





Here is my silverlight.live.com embedded video




Here is my embedded video from another site having the similar service. Feel the difference



shalvin.com

Friday, May 23, 2008

WebParts in Asp .Net

Before speaking about WebParts in Asp .Net let me speak a bit about iGoogle. Following is my iGoogle page.



















Here I can decide on what to appear on my page. I can add new Gadgets, remove Gadgets and change the location of gadgets.

Similar service are provided by Microsoft in my.msn.com as show in the figure.



















Web Parts
is Microsoft technology for creating personalized pages as seen in iGoogle. This is a part of Microsoft Portal Framework.

Start a new Asp .Net Project. Add a Table with 4 columns and 1 row.
Add a WebPartManager to the form.

Add a WebPartZone to each Table Data.

Into the first WebPart Zone add a Calendar.
Since the calendar is place inside a WebPart zone you will get an extender property called Title. Set an appropriate title.

If you run the application you will see extra menu options for Calendar contol as shown in the exhibit.
























Now you are in Browser Display Mode.

If you select the minimize option the the calendar will be minimized and next time you open the page the minimized state will be persisted.













WebParts Design Display Mode
WebParts supports multiple display mode. In Design Display Mode you can drag a control from one webpart zone to another.

Place a Command Button on the existing form. Change its text to Design. On clicking the Design Button you want to change the display mode to Design Display Mode.
Here is the code

protected void btnDesign_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
}

Now you can drag a control from one WebPartZone to another as shown in the figure below.

















CatalogDispalyMode for Adding Controls to WebPartZone

If you close the Calendar by select Close menu from the control there is no way the have the control back. Also you might want to add new Control (widgets) to a zone as Add Stuff option in iGoogle. For doing that you can use the CatalogZone and DeclarativeCatalogPart controls and setting the Display mode to Catalog Display mode.

So add a CatalogZone to the page. Add a DeclarativeCatalogPart to the CatalogZone. Select Edit Template from the Smart tag of DeclarativeCatalogPart.














Cut and past the calender control into the DeclarativeCatalogPart.

Add a Command Button give a text Catalog. On clicking the button you have change the Display mode to CatalogDisplay Mode.

Here is the code:
protected void btnCatalog_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}

Now when you click the button you will see the Catalog zone. From the catalog zone you can select the control and the WebPartZone to which you want to add the control.
















Now we can implement the BrowseDisplayMode which is the mode for end user browsing.
So Place another TextBox. Set the Text Propterty to Browser and write the following code:

protected void btnBrowse_Click(object sender, EventArgs e)
{
WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode;
}

WebParts and ASPNETDB Database
You might be wondering the the data is getting persisted. It is in the ASPNETDB.MDF file system database that is getting created inside App_Data folder of the project. The information is stored in aspnet_PersonalizationPerUser table as shown in the figure below.
















ASPNETDB Database is used in Membership, Profile and WebParts services of Asp .Net 2.0.

Asp.Net 2.0 Master Page and TreeView
Themes in Asp .Net
shalvinpd.blogspot.com

Ajax .Net I : Extension Controls in Visual Studio 2008

In this blog we are going see Script Manager, UpdatePanel and Timer in Action. I will demnostrate creating an Digital clock in the site.

Start a new ASP .Net Website.

Visual Studio comes with 5 Ajax Extension controls as shown below.












Drag a ScriptManager to the form.
Below the ScriptManager add an UpdatePanel.
ScriptManager is responsible for delivering scripts to the Browser
In Ajax .Net Partial Page update is made possible using UpdatePanel.
Add a Label and an Ajax Timer Control Ajax Controls into the UpdatePanel. Set the Enabled property to True and Interval to 1000 (milliseconds) for the Timer Control.

Double click on the Timer control you will be taken to Tick Event of Timer.
Write the code to display the current time as shown below:

protected void Timer1_Tick(object sender, EventArgs e)
{
lblTime.Text = System.DateTime.Now.ToString("T");
}

Run the application you will see that the time is getting updated without the web page making a postback to the server.











Related Blog

Ajax .Net II : Setting up Ajax Control Toolkit controls

Ajax .Net III : CalendarExtender Control

Ajax .Net IV : TextBoxWaterMarkExtender

Ajax .Net V : FilteredTextBoxExtender

Ajax .Net VI : ConfirmButtonExtender

Thursday, May 22, 2008

Microsoft Innovation Days: Cochin - May 30, 2008

Learn about building reliable, high performance applications with a super-rich user interactivity using Microsoft technologies, such as the Visual Studio 2008, SQL Server 2008, Windows Server 2008, Silverlight 2 beta 1 and Expression Studio.

For registration click here

Monday, May 19, 2008

.Net Globalization

Globalization is the process of designing and developing applications that function for multiple cultures.

Lets begin our discussion on .Net Globalization with an ASP .Net example. Start an asp. Net project. Go to web.config and type the following:






Place a Calendar control on the form. When you run the application you will see an Arabic calendar with the Hijri year.


















Displaying All Cultures

Here I am creating an array of CultureInfo class. CultureInfo class contains information about a culture like its name, Calendar, Day Names, Month Names, Currency Format, etc.

SpecificCulture is a culture type where there is language code as well as country code. Examples are ar-SA, ml-IN, fr-FR. Here the first portion represents the Language Code and the second portion represents the Country Code.
using System.Globalization;

private void Form1_Load(object sender, EventArgs e)
{
CultureInfo[] cis = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo ci in cis)
listBox1.Items.Add(String.Format( ci.ToString()));
}

Displaying DisplayName and NativeName and Day Names of a Selected Culture

























using System.Globalization;
private void Form1_Load(object sender, EventArgs e)
{
CultureInfo[] cis = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
foreach (CultureInfo ci in cis)
comboBox1.Items.Add(String.Format( ci.ToString()));
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
lstDetails.Items.Clear();
CultureInfo ci = new CultureInfo(comboBox1.Text);
lstDetails.Items.Add(ci.DisplayName.ToString());
lstDetails.Items.Add(ci.NativeName.ToString());
lstDetails.Items.Add("");
lstDetails.Items.Add("Day names");
string[] strDayNames = ci.DateTimeFormat.DayNames;
foreach (string strDay in strDayNames)
lstDetails.Items.Add(strDay);

lstDetails.Items.Add("");
lstDetails.Items.Add("Month Names");
string[] strMonthNames = ci.DateTimeFormat.MonthNames;
foreach(string strMonth in strMonthNames)
lstDetails.Items.Add(strMonth);
}



Related Blog
Globalization in Windows Forms - Application with multi language support


Happy Programming
shalvin.com

Friday, May 16, 2008

.Net : Introduction to Multi threading

The basic concept behind multi threading is to perform multiple tasks simultaneously. The success of an application depends on reducing the downtime. For example if the application is performing a lengthy printing task, the application should be in a position to perform other tasks also.

Listing Threads in a Process
using System.Diagnostics;
Process p;
private void Form1_Load(object sender, EventArgs e)
{
p = Process.GetProcessById(5944);
ProcessThreadCollection theTrheads = p.Threads;
foreach (ProcessThread pt in theTrheads)
listBox1.Items.Add(String.Format("{0} {1} {2}", pt.Id, pt.StartTime, pt.PriorityLevel ));
}

A Process is a running application. The above example lists all the threads found in a process whose Process Id is 5944.


The namespace used for creating multi threaded application is System.Threading. The Thread class is used for working with threads.

You create a thread by passing the method to ThreadStart delegate.

Here is a very simple multi threading example which simultaneously shows two messageboxes.

using System.Threading;

Thread t;
Thread t1;
private void Form1_Load(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(Hello));
t.Start();

t1 = new Thread(new ThreadStart(Shalvin));
t1.Start();

}
private void Hello()
{
for (int i = 0; i < 10;i++)
{
MessageBox.Show("Hello");
}
}

private void Shalvin()
{
for (int i = 0; i <10;i++)
{
MessageBox.Show("Shalvin");
}
}
}

Multithreaded Ellipse Application
(Courtesy Saji P Babu)

This example demonstrates Sleep method, suspending and resuming threads. The example simultaneously draws two ellipses in Panel controls.


using System.Threading;

Thread thread;
Thread thread1;
private void Form1_Load(object sender, EventArgs e)
{
ThreadStart threadStart = new ThreadStart(DrawEllipse);
thread = new Thread(threadStart);
thread.Start();

ThreadStart threadStart1 = new ThreadStart(DrawEllipse1);
thread1 = new Thread(threadStart1);
thread1.Start();
}
private void DrawEllipse()
{
Graphics g = panel1.CreateGraphics();
Random rnd = new Random();
for (int i = 0; i < 500;i++)
{
g.DrawEllipse(Pens.Blue, 0, 0, rnd.Next(this.Width), rnd.Next(this.Height));
Thread.Sleep(100);
}
}

private void DrawEllipse1()
{
Graphics g = panel2.CreateGraphics();
Random rnd = new Random();
for (int i = 0; i < 500; i++)
{
g.DrawEllipse(Pens.Blue, 0, 0, rnd.Next(this.Width), rnd.Next(this.Height));
Thread.Sleep(100);
}
}
}