I have a asp.net page on which I have placed a Button control which has OnClientClick and OnClick events as follows:
<asp:Button Text="Activate" ID="btnActivate" OnClientClick="return ValidateActivation()" OnClick="btnActivate_Click" runat="server" />
The javascript function fired on OnClientClick displays an alert and returns false if the validation fails.
Also, the javascript function fired on OnClientClick returns true if the validation fails. So in this case I expect the server side event to be fired. But the server side event is not fired.
Here is the javascript code for your reference:
function ValidateActivation() {
var selected = false;
$('#<%=(gvParent.ClientID%>').find("input:checkbox").each(function () {
if (this.checked == true) { selected = true; }
});
if (selected == false) {
var oWnd = alert("Select at least one Division/Sub-Division to activate.");
return false;
}
else {
return true;
}
}
Basically this is a javascript which checks that atleast one checkbox should be checked in the gvParent Gridview.
The alert condition works perfectly. But the page does not postback and the event btnActivate_Click is not fired even if the check box is checked.
I have verified that the control enters in the 'else' part of the statement.
Any suggestions, alternatives ?
Edit:
This is my page structure
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript" language="javascript">
.......my script here ...
</script>
</telerik:RadScriptBlock>
</Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
<telerik:RadScriptManager ID="radScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadAjaxLoadingPanel ID="lp1" runat="server" Skin="Outlook">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="ap1" runat="server" Width="100%"
LoadingPanelID="lpID1">
<telerik:RadPanelBar ClientIDMode="Static" ID="myid" runat="server"
OnClientItemClicking="onClicking" ExpandMode="SingleExpandedItem" önClientItemExpand="scrollToTop"
Skin="Windows7" Width="100%">
<Items>
<telerik:RadPanelItem runat="server" CssClass="new" Expanded="true" Text="my text"
Value="head1">
<Items>
<telerik:RadPanelItem runat="server" Value="info">
<ItemTemplate>
<asp:GridView ID="gvParent" runat="server"...