Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a ASP.NET Expert!

Join 416,729 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 2,940 people online right now.Registration is fast and FREE... Join Now!



date time picker Rate Topic: -----

#1 jainiraj  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 13-November 08


Dream Kudos: 0

Share |

date time picker

Posted 22 May 2009 - 03:26 AM

I want to use calender like date time picker in asp.net+c#. how can I add this calender or date time picker.
Was This Post Helpful? 0
  • +
  • -


#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • Icon

Reputation: 652
  • View blog
  • Posts: 3,488
  • Joined: 21-March 08


Dream Kudos: 1200

Expert In: .NET

Re: date time picker

Posted 22 May 2009 - 04:13 AM

you could look into using the AJAX Calendar.

http://www.asp.net/A...r/Calendar.aspx
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • Icon

Reputation: 380
  • View blog
  • Posts: 9,355
  • Joined: 26-December 05


Dream Kudos: 500

Expert In: Everything

Re: date time picker

Posted 22 May 2009 - 11:38 AM

Add a Calendar control to the page and use the Selectionchanged event to get the date and put it in a TextBox when the user selects a date.
Was This Post Helpful? 0
  • +
  • -

#4 woodjom  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 22
  • View blog
  • Posts: 515
  • Joined: 08-May 08


Dream Kudos: 50

Re: date time picker

Posted 29 May 2009 - 01:36 PM

Ok, so what if i have 3 text box with 3 buttons associated with them but only one calendar control.

I click the button it makes the calendar visible, at which point the user selects a date and its supposed to go to the text box.

Catch is...i dont have a calendar for each text box...just 1 calendar to feed 3 text boxes. I created a page-level variable...
Dim calTextBox As TextBox



which upon one of the buttons click does...
calTextBox = txtNewProjectStart
clndrNewProject.Visible = True



Then the user causes said event to happen...
Protected Sub clndrNewProject_Selectionchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles clndrNewProject.Selectionchanged
  calTextBox.Text = clndrNewProject.SelectedDate.ToString
  clndrNewProject.Visible = False
End Sub



But the catch is for some reason the variable calTextBox is not carrying the object reference of the output text box. Keep getting a NullReferenceException.

I tried doing...
Dim calTextBox As New Web.UI.WebControls.TextBox



except the data goes no where but everything in the calendar event completes.

Everything above is on the same form and is in the same view of a multiview.
Was This Post Helpful? 0
  • +
  • -

#5 Jayman  Icon User is offline

  • Student of Life
  • Icon

Reputation: 380
  • View blog
  • Posts: 9,355
  • Joined: 26-December 05


Dream Kudos: 500

Expert In: Everything

Re: date time picker

Posted 29 May 2009 - 07:55 PM

First off keep in mind that every time the page posts back everything is re-instantiated including the page itself. This means that your TextBox control is being created each time the page posts back. And since you are not using the New keyword you are getting the NullReferenceException.

I would suggest an alternative to the method you are attempting to use. Since you are only using one calendar control to populate three different textboxes, you need to know which button that is associated to each textbox initiated the Click event. Store the name of the button in a Session variable and then check that value in the Selectionchanged event of the calendar control.

To illustrate this, here is an example:

Here is the code for the page itself. 3 textboxes, 3 buttons, and 1 calendar control.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtDate1" runat="server"></asp:TextBox>
        <asp:Button ID="btnDate1" runat="server" Text="Date1" /><br />
        <asp:TextBox ID="txtDate2" runat="server"></asp:TextBox>        
        <asp:Button ID="btnDate2" runat="server" Text="Date2" /><br />
        <asp:TextBox ID="txtDate3" runat="server"></asp:TextBox>
        <asp:Button ID="btnDate3" runat="server" Text="Date3" /><br />
        <asp:Calendar ID="Calendar1" runat="server" Visible="false"></asp:Calendar>
    </div>
    </form>
</body>
</html>


Each button calls the same event. First create a button in the event and then cast the sender object to the correct type. The sender object will tell us which button called the event. Once we have the correct button, store the ID in a Session variable and then show the calendar.
	Protected Sub btnDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDate1.Click, btnDate2.Click, btnDate3.Click
		'create a new button
		Dim clickedButton As Button
		'cast the sender to the correct type, a Button
		clickedButton = CType(sender, Button)
		'store the Button ID in a Session variable
		Session("Buttonclicked") = clickedButton.ID
		'show the calendar
		Calendar1.Visible = True

	End Sub


Now in the Selectionchanged event of the calendar get the value stored in the Session variable and use it to determine the logical path to follow and put the date in the correct textbox. Lastly, hide the calendar control again until the next button is clicked.
	Protected Sub Calendar1_Selectionchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.Selectionchanged
		'verify that a Session variable is valid before attempting to use it
		If Session("Buttonclicked") <> Nothing Then
			'now check the session variable for the ID of the button
			'this will indicate which textbox to put the date into
			If Session("Buttonclicked").ToString().Equals("btnDate1") Then
				txtDate1.Text = Calendar1.SelectedDate.ToString()
			ElseIf Session("Buttonclicked").ToString().Equals("btnDate2") Then
				txtDate2.Text = Calendar1.SelectedDate.ToString()
			Else
				txtDate3.Text = Calendar1.SelectedDate.ToString()
			End If

		End If
		'hide the calendar
		Calendar1.Visible = False

	End Sub


I hope that helps explain a fairly simple method of accomplishing the task you desire.
Was This Post Helpful? 1
  • +
  • -

#6 woodjom  Icon User is offline

  • D.I.C Addict
  • Icon

Reputation: 22
  • View blog
  • Posts: 515
  • Joined: 08-May 08


Dream Kudos: 50

Re: date time picker

Posted 01 June 2009 - 07:10 AM

Yeah i keep forgetting about the postback event. As well, forgot about the session variables. Looks like ill be creating some variables in the session_start event in the app.config.

I have alot more togo, but thanx for bringing that old strategy back, havent used session variables since i started playing with PHP and then moved to ASP.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users