How do i use Calender control in VS 2003?

L

Learner

Hi there,
I have a text box in my webform to type in a date. I want to take
advantage and use the calender control to let the user just to click on

the clander and select a date. How do i program this? is there a link
with a code snippet?


Thanks
-L
 
N

Nathan Sokalski

Here is a small piece of code that does what you want:

Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles Calendar1.SelectionChanged

TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

Calendar1.SelectedDate = CDate(TextBox1.Text)

End Sub


Take note, however, that you need to have some way of doing a postback when
the TextChanged event occurs, such as a separate Button in which you can
place the code I put in the TextChanged event, or you can set the
AutoPostBack property to True. Although it is not a requirement, you may
also want to add validation to make sure the date entered in TextBox1.Text
is a valid date before attempting to assign it to Calendar1.SelectedDate.
Good Luck!
 
L

Learner

Hi Nathan,
Cool! Thanks much and appricate your time explaining this to me. I
liked it when you also consider the scenario of
TextBox!_TextChanged event. I will try implementing.
Thanks
-L
 
B

bhawin13

Hello

Find some javascript date picker control. That is freely available and
it will more suitable to you.

B
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top