I have a ComboBox and a button. The ComboBox is bound to a table of 'groups'. The button allows you to add a new 'group' record to that table if whatever is currently typed in the ComboBox doesn't match anything in the dropdown by calling the button's click event 'btnAddGroup_Click'
.
My problem is, even though my javascript function addGroup is being called with no problem... when the confirm is true... the server side click even 'btnAddGroup_Click' is not being called. When the confirm is false, I do not want the click even to to called.
Strangely, when I remove the 'return' from "return addGroup();" it will trigger my server side click event whether I say yes or no to the confirm. Am I making some fundamental JavaScript mistake?
function addGroup() {
var addgroupbutton = document.getElementById('<%= btnAddGroup.ClientID %>');
var changegroupbutton = document.getElementById('<%= btnSave.ClientID %>');
if (confirm('Are you sure you want to add a new group?')) {
addgroupbutton.disabled = true;
changegroupbutton.disabled = false;
alert("1");
return true;
}
else {
alert("2");
addgroupbutton.disabled = false;
changegroupbutton.disabled = true;
return false;
}
}
<telerik:RadComboBox ID="rcbAddCompanyGroup" runat="server" Width="310px" Height="150"
EmptyMessage="Select a Company Group" DataSourceID="SqlDataSource2"
DataTextField="CompanyGroup" OnClientItemsRequested="OnClientItemsRequested" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"
DataValueField="CompanyGroup" EnableAutomaticLoadOnDemand="True" ItemsPerRequest="20"
ShowMoreResultsBox="true" EnableVirtualScrolling="true" Filter="Contains">
</telerik:RadComboBox>
<asp:Button ID="btnAddGroup"
OnClick="btnAddGroup_Click"
OnClientClick="return addGroup();"
runat="server" Text="Add Group" Visible="true" Width="87px" />
Protected Sub btnAddGroup_Click(sender As Object, e As System.EventArgs)
If rcbAddCompanyGroup.Text.Trim.Length <> 0 Then
insertCompanyGroup()
End If
End Sub
.
My problem is, even though my javascript function addGroup is being called with no problem... when the confirm is true... the server side click even 'btnAddGroup_Click' is not being called. When the confirm is false, I do not want the click even to to called.
Strangely, when I remove the 'return' from "return addGroup();" it will trigger my server side click event whether I say yes or no to the confirm. Am I making some fundamental JavaScript mistake?
function addGroup() {
var addgroupbutton = document.getElementById('<%= btnAddGroup.ClientID %>');
var changegroupbutton = document.getElementById('<%= btnSave.ClientID %>');
if (confirm('Are you sure you want to add a new group?')) {
addgroupbutton.disabled = true;
changegroupbutton.disabled = false;
alert("1");
return true;
}
else {
alert("2");
addgroupbutton.disabled = false;
changegroupbutton.disabled = true;
return false;
}
}
<telerik:RadComboBox ID="rcbAddCompanyGroup" runat="server" Width="310px" Height="150"
EmptyMessage="Select a Company Group" DataSourceID="SqlDataSource2"
DataTextField="CompanyGroup" OnClientItemsRequested="OnClientItemsRequested" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"
DataValueField="CompanyGroup" EnableAutomaticLoadOnDemand="True" ItemsPerRequest="20"
ShowMoreResultsBox="true" EnableVirtualScrolling="true" Filter="Contains">
</telerik:RadComboBox>
<asp:Button ID="btnAddGroup"
OnClick="btnAddGroup_Click"
OnClientClick="return addGroup();"
runat="server" Text="Add Group" Visible="true" Width="87px" />
Protected Sub btnAddGroup_Click(sender As Object, e As System.EventArgs)
If rcbAddCompanyGroup.Text.Trim.Length <> 0 Then
insertCompanyGroup()
End If
End Sub