Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Show alert if datepicker is Empty and Save Record

0.00/5 (No votes)
6 Nov 2014CPOL 6K  
Show alert if datepicker is empty and save record

Sometimes, we need to show a message depending on the value (or blanks) of the fields in Client side (faster), and later call to OnClick event (server side) to save into database. For example, if our datePicker or texbox is null or empty. We can do it with get_selectedDate (in case of datepicker) with JQuery.

If we have textbox or other controls, we should look for the correct function here. We will have two events in our save button: OnClientClick (client) and Onclick (server).

JavaScript
<script src="../Scripts/jquery-1.5.min.js" 
type="text/javascript"></script>
<script type="text/javascript">
    function ShowMessageIfEmpty() {
    var rdpDate = $find("ctl00_mainContent_rdpDate");
    var date = rdpDate.get_selectedDate();
    if (date == null)
    {
      alert("Date is empty. you must fill it in the future. Record saved in database.");
    }
 }
</script>

Your datepicker and button in your page.aspx should be:

ASP.NET
<telerik:RadDatePicker ID="rdpDate" runat="server" Width="100%"
 PopupDirection="TopRight" Calendar-RangeMaxDate='<%# DateTime.Today %>'>
</telerik:RadDatePicker>

<asp:ImageButton ID="btnSave" runat="server"
OnClick="btnSave_click" OnClientClick="ShowMessageIfEmpty()" />

If this post helped you, please leave a comment.

Filed under: CodeProject, jquery

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)