nguvi

Here is my webpart code

protected DateTimeControl dtcDate;

protected override void CreateChildControls()

{

dtcDate = new DateTimeControl();

dtcDate.ID = "dtcDate";

dtcDate.DateOnly = true;

this.Controls.Add(dtcDate);

}

protected override void RenderContents(HtmlTextWriter writer)

{

try

{

ObjectItem item = ObjectManagement.GetObject(1);

dtcDate.SelectedDate = item.StartDate;

dtcDate.RenderControl(writer);

}

Can't set the item.StartDate to SelectedDate propertie of Sharepoint DateTimeControl!

Anyone know how

Ngvicu



Re: SharePoint - Development and Programming Can't Set SelectDate of DateTimeControl in RenderContents webpart

Matthew Lea

Please give a little more detail as to exactly what problem/error you are getting.





Re: SharePoint - Development and Programming Can't Set SelectDate of DateTimeControl in RenderContents webpart

nguvi

the value of item.StartDate = 8/8/2007

the date doesn't appear on the dtcdate control on the render

If i set the date on createchildcontrols() the date appear

-------------------

protected DateTimeControl dtcDate;

protected override void CreateChildControls()

{

dtcDate = new DateTimeControl();

dtcDate.ID = "dtcDate";

dtcDate.DateOnly = true;

dtcDate.SelectedDate = item.StartDate;

this.Controls.Add(dtcDate);

}

protected override void RenderContents(HtmlTextWriter writer)

{

try

{

ObjectItem item = ObjectManagement.GetObject(1);

dtcDate.RenderControl(writer);

}

but if i set the date on rendercontents nothing show up.





Re: SharePoint - Development and Programming Can't Set SelectDate of DateTimeControl in RenderContents webpart

Matthew Lea

Either call base.RenderContents or RenderChildren (depending on what you're trying to do) when you are ready to render the control.





Re: SharePoint - Development and Programming Can't Set SelectDate of DateTimeControl in RenderContents webpart

nguvi

protected DateTimeControl dtcDate;

protected TextBox txtName;

protected override void CreateChildControls()

{

dtcDate = new DateTimeControl();

dtcDate.ID = "dtcDate";

dtcDate.DateOnly = true;

dtcDate.SelectedDate = item.StartDate; <-- set the value

this.Controls.Add(dtcDate);

txtName = new TextBox();

txtName.ID = "txtName";

this.Controls.Add(txtName);

}

protected override void RenderContents(HtmlTextWriter writer)

{

try

{

ObjectItem item = ObjectManagement.GetObject(1);

dtcDate.SelectedDate = item.StartDate; <--doesn't set the value

dtcDate.RenderControl(writer);

txtName.Text = item.Name; <--set the value

txtName.RenderControl(writer);

}

Like you can see here.. i add a textbox and on render we see the value of the Name and not startdate.





Re: SharePoint - Development and Programming Can't Set SelectDate of DateTimeControl in RenderContents webpart

nguvi

I move the ObjectItem item = ObjectManagement.GetObject(1) in the createchildcontrols() and set all value there and it work.





Re: SharePoint - Development and Programming Can't Set SelectDate of DateTimeControl in RenderContents webpart

Raju Indukuri

dtcDate.ClearSelection(); // add this line.

dtcDate.SelectedDate = item.StartDate; // it sets value.

I have no clue why we should ClearSelection before setting an other value outside CreateChildControls() function as this is not common in programming. But this works in this case.