ASP.Net AJAX CalendarExtender Error: String was not recognized as a valid DateTime

Last Reply 23 days ago By dharmendr

Posted 23 days ago

i am using ajax calender extender.

<asp:CalendarExtender ID="cal_ext_1" TargetControlID="txt_attendance"  Format="dd/mmm/yyyy" runat ="server"></asp:CalendarExtender>
cmd.Parameters.AddWithValue("@EMP_ATTENDANCE", Convert.ToDateTime(txt_attendance.Text)); 

getting error

An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code

Additional information: String was not recognized as a valid DateTime.

You are viewing reply posted by: dharmendr 23 days ago.
Posted 23 days ago

Hi Nandhu,

Check this example. Now please take its reference and correct your code.


<asp:ScriptManager runat="server" />
<asp:TextBox ID="txt_attendance" runat="server" />
<asp:CalendarExtender ID="cal_ext_1" TargetControlID="txt_attendance" Format="dd/MMM/yyyy"
<asp:Button Text="Save" runat="server" OnClick="Save" />



protected void Save(object sender, EventArgs e)
    DateTime dt = DateTime.ParseExact(txt_attendance.Text, "dd/MMM/yyyy", null);
    ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('" + dt + "')", true);


Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs)
    Dim dt As DateTime = DateTime.ParseExact(txt_attendance.Text, "dd/MMM/yyyy", Nothing)
    ClientScript.RegisterClientScriptBlock(Me.GetType(), "", "alert('" & dt & "')", True)
End Sub