Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

preventing server side execution on validation failure

$
0
0

Hi,

I have two textboxes with ajax calendar extenders and I am trying to apply validations around those textboxes. Validation seems to be working fine but when validation fails, my server side methods are getting called and throws exceptions..
Which I don't want.
How do I stop the server side methods once the validation through javascript fails?
Here is what I am doing..
My two textboxes with calendar extenders and validators. I am using 'OnClientDateSelectionChanged' on calendarextender and calling this javascript function.

<td>Date Range:<asp:TextBox ID="txtDate" runat="server" AutoPostBack="true" OnTextChanged="txtDate_TextChanged1" ValidationGroup="MKE">1/1/2015</asp:TextBox><ajaxToolkit:CalendarExtender ID="txtDate_CalendarExtender" runat="server" BehaviorID="txtDate_CalendarExtender" TargetControlID="txtDate" OnClientDateSelectionChanged="return checkDate();"></ajaxToolkit:CalendarExtender><asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtDate" Display="Dynamic" ErrorMessage="Invalid Date" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator><ajaxToolkit:ValidatorCalloutExtender ID="CompareValidator1_ValidatorCalloutExtender"
                        runat="server" Enabled="True" TargetControlID="CompareValidator1"></ajaxToolkit:ValidatorCalloutExtender>&nbsp; To &nbsp;<asp:TextBox ID="txtDate1" runat="server" AutoPostBack="true" OnTextChanged="txtDate1_TextChanged" ValidationGroup="MKE1">12/31/2015</asp:TextBox><ajaxToolkit:CalendarExtender ID="txtDate1_CalendarExtender" runat="server" BehaviorID="txtDate1_CalendarExtender" TargetControlID="txtDate1"></ajaxToolkit:CalendarExtender><asp:CompareValidator ID="CompareValidator2" runat="server" ControlToValidate="txtDate1" Display="Dynamic" ErrorMessage="Invalid Date" Operator="DataTypeCheck" Type="Date"></asp:CompareValidator><ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender1"
                        runat="server" Enabled="True" TargetControlID="CompareValidator2"></ajaxToolkit:ValidatorCalloutExtender></td>
<script type="text/javascript">

        function checkDate(sender, args) {
            //debugger;
            if (sender._selectedDate > new Date()) {
                //create a new date var and set it to the
                //value of the senders selected date
                var selectedDate = new Date();
                selectedDate = sender._selectedDate;
                //create a date var and set it's value to today
                var todayDate = new Date();
                var mssge = "";

                if (selectedDate > todayDate) {
                    //set the senders selected date to today
                    sender._selectedDate = todayDate;
                    //set the textbox assigned to the cal-ex to today
                    sender._textbox.set_Value(sender._selectedDate.format(sender._format));
                    //alert the user what we just did and why
                    alert("Warning! - Date Cannot be in the future");
                    return false;
                }
            }

        }

    </script>

Please guide me through this. Thanks for any help.


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>