0

My condition:
enter image description here:
My code:


$('#' + '<%=txtFrom.ClientID%>').datepicker({ dateFormat: 'yy-mm-dd' });


I only want to choose a date in 'yy-mm-dd' format.If it chosen from Datepicker its work.But textbox allow to enter date manually which is not in a format. How can i force user to select date from Datepicker not manually?

tutankhamun
  • 880
  • 2
  • 11
  • 21
4b0
  • 21,981
  • 30
  • 95
  • 142

6 Answers6

2
protected void Page_PreRender(object sender, EventArgs e)
{
    txtFrom.Attributes["readonly"] = "readonly";
}
Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
0

You can use jquery tool's library date picker. Its very simple to use and its automatically disable manual input.

<script src="src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script>

<!-- dateinput styling -->
<link rel="stylesheet" type="text/css" href="dateinput.css"/>

<!-- HTML5 date input -->
<input type="date" />

<!-- make it happen -->
<script>
  $(":date").dateinput();
</script>

For more info please refer jquery tools

0

I guess you are wanting to disable text input for the input box, is it? If so, this has been already discussed earlier. Please refer this.

Community
  • 1
  • 1
PCoder
  • 2,165
  • 3
  • 23
  • 32
0

I could suggest you to mask it also.

Here is the code.

<input type="text" id="dtp" />​

and javascript:

$("#dtp")
    .datepicker({ dateFormat: 'yyyy-mm-dd' })
    .mask("9999-99-99");​

I used this library.

This is a working demo. You can play with it to fit your needs.

EDIT

I've updated the demo. There is a caveat with mixing these two plugins. However I've managed correct it somehow. Not the most elegant solution but works. ))

Oybek
  • 7,016
  • 5
  • 29
  • 49
0

you can use that function for that text box. write that jquery in your script file.

  <script type="text/javascript" >
    $(document).ready(function ($) {
         $('#<%=txtFrom.ClientID%>').keypress(function () {
            return false;
        });
    });
 </script>

paste that code it will not allow u to press any key from keyboard when your focus is in your text box. 100% tested code.

Bilal lilla
  • 618
  • 3
  • 8
  • 29
0

Add readonly attribute to this input

readonly="readonly"

y.selivonchyk
  • 8,987
  • 8
  • 54
  • 77