Creating date time picker control for asp.net

This is a very simple control to create and to have with very cool results.


Create a user control and just paste in the code:

Code snipet:
ASCX:
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" media="screen" href="//tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">

<%----%>
<script type="text/javascript" src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="//tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="//tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.pt-BR.js"></script>

<div id="DateTimePicker" class="input-append date">
    <asp:TextBox id="txtGetDateTime" runat="server" EnableViewState="true" ViewStateMode="Enabled" />
    <span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
</div>

<script type="text/javascript">
    $('#DateTimePicker').datetimepicker({
    format: 'dd/MM/yyyy hh:mm:ss',
    language: 'en-EN'
    });
</script>
Very important to mention in the TextBox ViewState = “true” !

ASCX.CS:
public DateTime GetDateTime
{
       get { return GetSetDateTimeProperty(); }
}

private DateTime GetSetDateTimeProperty()
{
       var txt = txtGetDateTime.Text;
       DateTime oDt; DateTime.TryParse(txt, out oDt);
       return oDt;

}

Comentarii

Postări populare de pe acest blog

RpiCar

DevExpress Theme Changer ...