Re: How do I pass a DateTime to a custom control ?

From: Alan Silver (alan-silver_at_nospam.thanx)
Date: 02/22/05


Date: Tue, 22 Feb 2005 19:46:20 +0000

Jon,

Thanks for the reply, but either I didn't make myself clear or you
misread the question ;-)

I have the property set/get code working fine, my problem is how to use
this in the calling page. I would like to be able to do something like
...

<MyControls:DateTimePicker ID="dtpDTP" DateTimeDT="<%=DateTime.Now()%>"
Runat="Server" />

but this gives the error "<%=DateTime.Now()%> is not a valid value for
DateTime". I tried adding ToString() on to that as well, but that gave
the same error.

Your code did the same. I think the problem is in the way I'm passing
the value to the control. I can set the property fine in code ...

dtpDTP.DateTimeDT = dateTime.Now;

I just can't set it in the tag.

Any ideas? Thanks again.

>Try this:
>
>public DateTime DateTimeDT {
> get {
> return m_dtDateTime;
> }
> set {
> m_dtDateTime = value;
> }
>}
>
>where m_dtDateTime is a private or protected instance variable of type
>DateTime.
>
>
>"Alan Silver" <alan-silver@nospam.thanx> wrote in message
>news:t4kwbyKKs3GCFw1V@nospamthankyou.spam...
>> Hello,
>>
>> I have a custom control that displays the date and time. I currently have
>> properties for the day, month, year, hour and minute, which have to be set
>> separately. This is inefficient.
>>
>> I would like to have one property that I can use to pass in a DateTime,
>> and have the control pull out the various bits from that. I tried ...
>>
>> public DateTime DateTimeDT {
>> get {
>> return new DateTime(m_Year, m_Month, m_Day, m_Hour, m_Minute, 0);
>> }
>> set {
>> m_Year = value.Year;
>> m_Month = value.Month;
>> m_Day = value.Day;
>> m_Hour = value.Hour;
>> m_Minute = value.Minute;
>> }
>> }
>>
>> but when I try and use this in code ...
>>
>> DateTimeDT="<%=DateTime.Now()%>"
>>
>> I get the error "<%=DateTime.Now()%> is not a valid value for DateTime".
>>
>> Please could someone enlighten me as to a) what I'm doing wrong and b) the
>> correct/best/easiest way to do this? TIA
>>
>> --
>> Alan Silver
>> (anything added below this line is nothing to do with me)
>
>

-- 
Alan Silver
(anything added below this line is nothing to do with me)


Relevant Pages

  • Re: Bug in DateTimePicker.cs
    ... /// Specifies the date and time format the DateTimePicker control displays. ... SolidBrush m_brushDisabled; ... private DateTime minDate = DateTime.MinValue; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: System.Windows.Forms.DateTimePicker
    ... even the masked textbox has issues. ... Dim dateAppt As DateTime ... Microsoft might possibly be the most defective control ever foisted ... NOT fire some of the times when a user changes the checked property ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: System.Windows.Forms.DateTimePicker
    ... Clear the DTPs on Form Load ... Dim dateAppt As DateTime ... Microsoft might possibly be the most defective control ever foisted ... NOT fire some of the times when a user changes the checked property ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: System.Windows.Forms.DateTimePicker
    ... Clear the DTPs on Form Load ... Dim dateAppt As DateTime ... Microsoft might possibly be the most defective control ever foisted ... NOT fire some of the times when a user changes the checked property ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: System.Windows.Forms.DateTimePicker
    ... Clear the DTPs on Form Load ... Dim dateAppt As DateTime ... Microsoft might possibly be the most defective control ever foisted upon ... problem is the catching of the event of change of Checked property. ...
    (microsoft.public.dotnet.framework.windowsforms.controls)