如何阻止带复选框的RadComboBox下拉框关闭时触发回发
Solution for RadComboBox Checkbox Postback Only on ItemChecked (Not Dropdown Close)
The issue you're facing comes from RadComboBox's default AutoPostBack="true" behavior—it triggers a postback both when an item is checked and when the dropdown panel closes. To fix this, we'll disable the automatic postback and manually trigger it only when an item's checkbox is toggled.
Step 1: Modify the RadComboBox Markup
Update your control to disable AutoPostBack and add a client-side event handler for when items are checked:
<telerik:RadComboBox RenderMode="Lightweight" ID="RadComboBox1" runat="server" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" CssClass="modaldropdown" ZIndex="99999999" Width="600px" Label="Select book genres:" OnDataBound="RadComboBox1_DataBound" OnItemChecked="RadComboBox1_ItemChecked" AutoPostBack="false" <!-- Disable automatic postback --> OnClientItemChecked="onItemChecked"> <!-- Add client-side check handler --> <ItemTemplate> <ul> <li> <strong>Name: </strong> <%# DataBinder.Eval(Container.DataItem, "Name")%> </li> <li> <strong>Email: </strong> <%# DataBinder.Eval(Container.DataItem, "Email")%> </li> <li> <strong>Department: </strong> <%# DataBinder.Eval(Container.DataItem, "DepartmentName")%> </li> <li> <strong>Division: </strong> <%# DataBinder.Eval(Container.DataItem, "DivisionName")%> </li> </ul> </ItemTemplate> </telerik:RadComboBox>
Step 2: Add Client-Side Script to Trigger Postback
Add this script block to your page to manually initiate a postback when an item is checked/unchecked:
<script type="text/javascript"> function onItemChecked(sender, args) { // Trigger the server-side OnItemChecked event explicitly sender.fireCommand("ItemChecked", ""); } </script>
Step 3: Keep Your Server-Side Code
Your existing C# code works as-is, since the fireCommand call will trigger the OnItemChecked event just like the original auto-postback:
protected void RadComboBox1_ItemChecked(object sender, RadComboBoxItemEventArgs e) { string r = e.Item.Text; string rw = e.Item.Value; // Add your business logic here (e.g., update selections, filter data) }
How This Works
- Disabling
AutoPostBack: Stops the control from triggering a postback when the dropdown panel closes, which was the unwanted behavior. - Manual Postback via
fireCommand: TheonItemCheckedclient function callssender.fireCommand("ItemChecked", ""), which directly invokes the server-sideOnItemCheckedevent—this ensures a postback only when an item's checkbox is toggled. - Full Compatibility: This approach works with the
EnableCheckAllItemsCheckBoxtoo—checking/unchecking the "Select All" box will trigger theItemCheckedevent for all affected items, resulting in the expected postback behavior.
内容的提问来源于stack exchange,提问作者Rohil Patel
相关产品推荐
相关产品推荐

