locked
Sharepoint DateTime Control queries RRS feed

  • Question

  • 1. I am creating a custom newform.aspx page, where I used Sharepoint DateTime Control. Because of some space limitation page, I want to reduce width of SharePoint DateTime Control. I notice that control dont have width property, Please let me know how can I do this?

    2. I have added two Sharepoint datetime control box as "From Date" and "To Date" and compare the date that To Date should Greater Than or Equal to "From Date". See following sample, let me know what I am missing?

    From Date : 05/14/2010 11:30 AM

    To Date : 05/14/2010 110:00 AM

    It wont validate this. Following is tag code

    //From Date//
    ----------
            <SharePoint:DateTimeControl runat="server" ID="txtFrom" DateOnly="false" HoursMode24="true" />
            <asp:RequiredFieldValidator ID="reqTxtFrom" runat="server" ControlToValidate="txtFrom$txtFromDate"
              ErrorMessage="* Required value" Display="Dynamic"><img src="/_layouts/images/info16by16.gif"/> Enter Start Date</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="compTxtFromToday" runat="server" ControlToValidate="txtFrom$txtFromDate"
              Operator="GreaterThanEqual" Display="Dynamic" Type="Date"><img src="/_layouts/images/info16by16.gif"/> Start Date should not less than Today's Date</asp:CompareValidator>
    
    //To Date
    //--------
            <SharePoint:DateTimeControl runat="server" ID="txtEnd" DateOnly="false" HoursMode24="true"/>
            <asp:RequiredFieldValidator ID="reqTxtEnd" runat="server" ControlToValidate="txtEnd$txtEndDate"
              ErrorMessage="* Required value" Display="Dynamic"><img src="/_layouts/images/info16by16.gif"/> Enter End Date</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="MyEndDate" runat="server" Display="Dynamic" ControlToValidate="txtEnd$txtEndDate"
              Type="Date" Operator="DataTypeCheck"><img src="/_layouts/images/info16by16.gif"/> Enter Valid Date</asp:CompareValidator>
            <asp:CompareValidator ID="cv" runat="server" Display="Dynamic" ForeColor="red" Type="date"
              Operator="GreaterThanEqual" ControlToCompare="txtFrom$txtFromDate" ControlToValidate="txtEnd$txtEndDate"><img src="/_layouts/images/info16by16.gif"/> End Date should not less than Start Date</asp:CompareValidator>
    

     

    Friday, May 14, 2010 9:16 PM

Answers

All replies

  • Hi,

    1. Try to place the DateTime control into a HTML element that has fixed with (e.g. a TD tag).

    2. You can create a custom field for validations:

    Cross field, cross item, cross list or even more complicated validations on SharePoint forms
    http://pholpar.wordpress.com/2010/01/04/cross-field-cross-item-cross-list-or-even-more-complicated-validations-on-sharepoint-forms/

    Peter

    • Marked as answer by Chengyi Wu Friday, May 21, 2010 2:42 AM
    Friday, May 14, 2010 11:11 PM
  • 1. For reducing the width put following style under <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">. Here basically you are overriding ".ms-input" in your web part page.

    <style type="text/css" >
    
    .ms-input 
    
    { width: 50px; }
    
    </style>
    </ asp:Content>
    

    You can also change the width using javascript/jquery, reviw following url

    http://mdasblog.wordpress.com/2008/12/30/setting-multi-select-widths-in-a-sharepoint-editformaspx-using-javascript/

     

     


    Ashish Kanoongo, MCP, MCSD, MCTS
    • Marked as answer by Courlett Friday, May 21, 2010 5:29 AM
    Saturday, May 15, 2010 3:54 AM
  • Hi,

    1. Altering on your page .ms-input affects all HTML elements using that style. That may be no problem, but if it is, you can apply the technique illustrated in this post to inject CSS style element from server side code for the specific DateTime control:

    Disabling the text box associated with the DateTimeControl from code
    http://pholpar.wordpress.com/2009/12/03/disabling-the-text-box-associated-with-the-datetimecontrol-from-code/

    2. @Ashish (for your deleted comment): In my understandig it is two field controls belonging to two datetime field, but at the second read you might be right. You should not have to delete this comment. I see nothing wrong with that.

    Peter

    • Marked as answer by Chengyi Wu Friday, May 21, 2010 2:42 AM
    Saturday, May 15, 2010 7:28 AM
  • Hello

    I have only 4 controls in 1 row, so I implemented Ashish suggestion by ading style in custom form.

    @Peter, I also reviewed your suggestion, but currently I need to implement only one small form.

    Friday, May 21, 2010 5:31 AM
  • Provided below are code samples written in C# to format an input as per SharePoint DateTime field.
    /* -- Format for Date Only Field -- */      
    private static String ToSPDate(String strDt)
    {
        if (strDt == String.Empty)
            return strDt;
        else
            return (Convert.ToDateTime(strDt)).ToString("yyyy-MM-dd");
    }
     

    Cheers, Eliza
    Thursday, June 17, 2010 12:37 PM