I am trying to prevent postback of the page using JQuery.
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#<%= btnAddAircraft.ClientID %>').click(function() {
var Passengers = $('#<%= txtPassengers.ClientID %>').val();
if (parseInt(Passengers) == 0)
{
$('#<%= txtPassengers.ClientID %>').focus();
alert("Number of passengers should not be Zero.");
return false;
}
});
});
<telerik:radbutton id="btnAddAircraft" onclick="btnAddAircraft_Click" validationgroup="P1" text="Add Aircraft" runat="server"> </telerik:radbutton>
The Validation process occurs but cannot retain the control to prevent postback.
Note: This issue I have handled using OnClientClick
event of RadButton
. But I want to work it out in my document.ready
function.
You want to attach to the OnClientClicking client-side event, which can be cancelled. Telerik uses for events Clicking/Clicked event names. See the events for more information: http://demos.telerik.com/aspnet-ajax/button/examples/clientsideevents/defaultcs.aspx
To cancel, you should be able to set e.set_cancel(true);
Because it's ASP.NET AJAX, you can't attach to AJAX components in document.ready; the AJAX isn't initialized in time for that to work.