[Solved] jQuery DateTimePicker selected value is null in code behind in ASP.Net

Last Reply 9 months ago By dharmendr

Posted 9 months ago

Mostly for gridview, we just use row.findcontrol and get its text value

Also in my case, my textbox is in a regular form not inside a gridview

Then why textbox.text returns null ?


DateTimePicker in ASP.Net GridView using jQuery DateTimePicker Plugin

You are viewing reply posted by: dharmendr 9 months ago.
Posted 9 months ago
mcp111 says:
Then why textbox.text returns null?

 The value is assigned at client side to TextBox. So you are getting null.

To get the value Request.Form collection is used.

Refer below code.


<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jquery.dynDateTime.min.js" type="text/javascript"></script>
<script src="Scripts/calendar-en.min.js" type="text/javascript"></script>
<link href="Styles/calendar-blue.css" rel="stylesheet" type="text/css" />
<link href="Styles/calendar-blue.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(function () {
            showsTime: true,
            ifFormat: "%Y/%m/%d %H:%M",
            daFormat: "%l;%M %p, %e %m,  %Y",
            align: "BR",
            electric: false,
            singleClick: false,
            displayArea: ".siblings('.dtcDisplayArea')",
            button: ".next()"
    <asp:TextBox ID="txtDOB" runat="server" ReadOnly="true" class="Calender" />
    <img src="calender.png" />
    <br />
    <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />


protected void btnSave_Click(object sender, EventArgs e)
    DateTime dob = Convert.ToDateTime(Request.Form["txtDOB"]);
    //Save the date to Database here.


Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Save the date to Database here.
End Sub