0

I have a visual webpart that uses several SP DateTimeControls (set to DateOnly) on a specific spot on the page. Those controls were simply added in VS to the ascx page from the toolbox like this: <SharePoint:DateTimeControl ID="DateControl1" runat="server" DateOnly="True" />. However, when the webpart is loaded up the controls are inoperative. I've looked around for how to initialize them and found references like this one that say to do it in the .cs page like this:

protected override void CreateChildControls()
{
    base.CreateChildControls();
    datetimepicker= new DateTimeControl();
    datetimepicker.ID = "datetimeControl1";
    this.Controls.Add(datetimepicker);
    // initialize other controls
}

...but that adds a new control at the top of the page instead of where I have already placed it. What step am I missing here?

Edit: To clarify, when the controls appear on the page the calendar button does not respond when clicked, and the date values that they are supposed to display (set from SQL values during page load) do not show up. The controls are in an UpdatePanel and all other controls with values loaded from SQL display properly.

1

first make sure you register the datetime control

<%@ Register Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebControls" TagPrefix="dtc" %>

<dtc:DateTimeControl ID="SetExpirynDateDateTimeControl" DateOnly="true" runat="server"
                        IsValid="True"></dtc:DateTimeControl>  

codebehind pageinit if !postback:

((TextBox)(SetExpirynDateDateTimeControl.Controls[0])).Attributes.Add("readonly", "readOnly");
4
  • Why do the readonly and readOnly attributes make a difference in this case?
    – thanby
    Sep 2 '14 at 17:56
  • this shld explain you more in depth about the readonly field
    – Nikhil J
    Sep 2 '14 at 18:07
  • While the advice is good, this answer doesn't actually fix my issue. The problem is that the calendar button is completely inoperative (despite being registered) when they appear on the page. See my edit above for a more thorough explanation.
    – thanby
    Sep 3 '14 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.