65.9K
CodeProject is changing. Read more.
Home

Show alert if datepicker is Empty and Save Record

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Nov 6, 2014

CPOL
viewsIcon

5950

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).

<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:

<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