Click here to Skip to main content
15,881,844 members
Articles / All Topics

Show alert if datepicker is Empty and Save Record

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
6 Nov 2014CPOL 5.8K  
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)


Written By
Software Developer (Senior)
Spain Spain
My name is Víctor Sumozas. I am an Industrial engineer and passionate exponent and enthusiast in software development and a keen interest in continuing evolution of .Net technologies. Certificated in Developing ASP.NET 4.5 MVC 4 Web Applications.
You can read the original post at Sumozas Null Pointer
Any comment will be highly appreciated. Thanks!

Comments and Discussions

 
-- There are no messages in this forum --