Null reference at sharepoint Datetime control error ?

HI

I am using Datetime control in .aspx page,two datetimecontrol startdate, and enddate, my code is like

timespan ts=new timespan(14,0,0,0);

dtcstartdate.selecteddate=datetime.today.subtract(ts);

dtcenddate.selectedate=datetime.now.adddays(-2);

in logs i am getting error as instance of an object not set to an instance at microsoft.sharepoint.datetimecontro.render(),this is the error i found in logs file

please can anybody give solution for this what it is actually i am new to sharepoint, unable to find this error please help me,

CAN ANYBODY PLEASE TELL ME  WHAT THIS ERRO AND Y I AM GETTING THIS ERROR I HAVE TRIED DATEONLY "TRUE" BUT IT DOESNT WORK.

PLEASE CAN ANYBODY PROVIDE SOLUTION FOR THIS

THANKS AND REGARDS

MAHESH


September 23rd, 2013 12:55pm

Have you set the SelectedDate property of the DateTime control? That might be why you are getting the null reference exception. 

E.g.

var t = DateTime.Now;
yourDateTimeControl.SelectedDate = t;
//Or, if you want to manipulate the date
yourDateTimeControl.SelectedDate = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, 0).AddDays(1);

Free Windows Admin Tool Kit Click here and download it now
September 23rd, 2013 1:20pm

Thanks for the answer,

I have tried the solution Maththew,but same error repeating please i have explained briefly what is my problem can you lookat my question again if you dont mind.

Thanking you in Advance

Regards

Mahesh

September 24th, 2013 2:19am

hi

where are your code? in page load? control event? inside a loop?
plz explain more about your code

Free Windows Admin Tool Kit Click here and download it now
September 24th, 2013 4:41am

my code is in page load()

{

//this is the code for selected startdate and enddate i am taking,

timespan ts=new timespan(14,0,0,0);

dtcstartdate.selecteddate=datetime.today.subtract(ts);

dtcenddate.selectedate=datetime.now.adddays(-2);

loadcompanylist();

}

buttonevent_click(0

{

loadcompanylist();

}

loadcompanylist()

{

startdate=dtcstartdate.selecteddate;

enddate=dtcendate.selecteddate;

}

i have one linkbutton in data list,when i am clicking that link the page it self is not loading,

it is generating correlation id and dats it.



September 24th, 2013 5:22am

after pageload and befor buttonevent(buttonevent_click), asp.net copies viewstate values to controls, so dtcstartdate and dtcendate values will be equal to values entered in form, not values assigned in pageload. it may be that values of that controls is null, when page postbacking.
Free Windows Admin Tool Kit Click here and download it now
September 24th, 2013 5:54am

Thanks for the reply

How can i set correct values can you please explain me briefly please.

how to set viewstate values here please

thank you 

regards

mahesh

September 24th, 2013 6:02am

use code as bellow:
loadcompanylist()
        {
            timespan ts = new timespan(14, 0, 0, 0);
            startdate = dtcstartdate.selecteddate ?? datetime.today.subtract(ts);
            enddate = dtcendate.selecteddate ?? datetime.now.adddays(-2);
        }
so if your controls contains values, it use them, else it use default values
Free Windows Admin Tool Kit Click here and download it now
September 24th, 2013 6:07am

it is saying that ?? symbol is not allowed for datetime controls here

September 24th, 2013 6:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics