Wednesday, March 25, 2009

ASP.NET AJAX and Calendar Control

Normally when we use calendar control in asp.net we see that calendar control occupies lot of space and selecting a date will cause a post back.

To avoid that problem we can use AJAX to select a date from calendar control with out any page post back and hiding the calendar control will save lot of space.

Now lets create a web application and add a script manager and a update panel control, now under update panel add text box, button and a calendar control as shown the below screen shot and make calendar control visible property to false

image

Now lets write logic in .cs file for that double click on Button and add following code

Calendar1.Visible = true;

and double click on calendar control and add following code

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
    Calendar1.Visible = false;
}

 

Now we are ready with our code, lets run build and test.

 

image

 

Hope this helps.

 

No comments:

Post a Comment