Question

i am creating web application with c# web forms. i need two date pickers to select date interval. However i can't find any default datepicker. calendar server control does not suit me because calendar is big and there is no option to resize it. I found a solution to programically add date picker control from system.windows.controls namespace, but my visual studio does not see datepicker class on that namespace. Does anyone know how to solve that situation? any help would be appreciated

Was it helpful?

Solution

One of the quickest ways to achieve this is to use a 3rd party client-side datePicker such as that from JQueryUI.

http://jqueryui.com/datepicker/

You will also need JQuery itself: http://jquery.com/download/

You would add textboxes to your document:

<asp:textbox: id="startDate" runat="server" cssclass="datepicker-field"/>

You can then add javascript to state that you would like all textboxes with a particular css class to become datepickers:

<script>
    $(document).ready(function(){
         $('.datepicker-field').datepicker();        
    });
</script>

After your form posts-back you will be able to get the selected date value as a string from startDate.Text

So you will have to parse and validate the value

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top