Tuesday, January 8, 2013

SharePoint:DateTimeControl readonly textbox + SharePoint 2010

my date control id is "dtSummaryDate" Please change the name with your date control id.


<SharePoint:DateTimeControl Enabled="false" runat="server" ID="dtSummaryDate
" DateOnly="true" />


<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">


<script language="javascript" type="text/javascript">

        _spBodyOnLoadFunctionNames.push("ReadOnlyTexbox");

        function ReadOnlyTexbox()
        {
            var x = document.getElementsByTagName("INPUT");

            alert(x.length);

            for (var i = 0; i < x.length; i++) {
                if (x(i).id.indexOf("dtSummaryDate") > 0) {

                   // alert(x(i));
                    //x(i).disabled = 'disabled';
                    x(i).setAttribute('readonly', 'readonly');
                }
            }
         }      
       
    </script>
 </asp:Content>

1 comment:

  1. Thanks Surya,

    For sharing this code,it work for me.

    ReplyDelete

Followers