This is a migrated thread and some comments may be shown as answers.

RadComboBox TextChanged event fires on button click

6 Answers 423 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nina
Top achievements
Rank 1
Nina asked on 09 Mar 2015, 03:43 PM
I have a problem with the OnTextChanged event of the RadComboBox. The combobox looks like this:

<telerik:RadComboBox ID="RadCB"  runat="server" Width="130px" AutoPostBack="true" OnTextChanged="RadCB_TextChanged" CheckBoxes="true" EnableCheckAllItemsCheckBox="true" Localization-CheckAllString="(All)" EmptyMessage="Select" CheckedItemsTexts="FitInInput" DropDownWidth="210px" MaxHeight="400px">
</telerik:RadComboBox>

It has some default values selected on page load. Then I change the values of a different combobox and click the search button.

Somehow the OnTextChanged event of the combobox above is fired even though the text and the selected values have NOT changed, which causes the values of the second combobox to be changed again. Is this the designed behavior?

Ajax is enabled on the page and both comboboxes are in the AjaxControls of the button.

Any help will be appreciated.

6 Answers, 1 is accepted

Sort by
0
Nina
Top achievements
Rank 1
answered on 09 Mar 2015, 03:44 PM
My Telerik version is 2015Q1
0
Ivan Danchev
Telerik team
answered on 11 Mar 2015, 01:50 PM
Hello,

We would need to see your code-behind to be able to reproduce the issue and determine where it originates.

I am attaching a sample project containing two RadComboBox controls to this reply. Please, try to reproduce the issue in it and post the .aspx and code-behind.

Regards,
Ivan Danchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Nina
Top achievements
Rank 1
answered on 12 Mar 2015, 03:45 PM
Please see the code below:

protected void Page_Load(object sender, EventArgs e)
{
Form.DefaultButton = Button1.UniqueID;
Button1.Focus();

if (!Page.IsPostBack)
{
RadComboBox2.DataBind();
SetStandardFilter();
}
}

protected void Button1_Click(object sender, EventArgs e)
{
// raises postback in this example
}

protected void RadComboBox2_TextChanged(object sender, EventArgs e)
{
// selected values changes -> refresh dependend combo
var values = RadComboBox2.CheckedItems.Select(item => item.Value).ToList();
FillRadComboBox1(values);
}

private void FillRadComboBox1(List<string> values)
{
// does some filtering and databinding in real life, but can be empty for demonstration purposes
}

private void SetStandardFilter()
{
// Set some default values that are selected in the combobox (RadComboBox2)
var defaults = new List<string>() {"1", "16", "17", "20"};

foreach (var defaultValue in defaults)
{
if (RadComboBox2.Items.FindItemByValue(defaultValue) != null)
{
var item = RadComboBox2.Items.FindItemByValue(defaultValue);
item.Checked = true;
}
}

// Fill RadComboBox1
var values = RadComboBox2.CheckedItems.Select(item => item.Value).ToList();
FillRadComboBox1(values);
}
0
Nina
Top achievements
Rank 1
answered on 12 Mar 2015, 03:47 PM
And .aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
<style type="text/css">
</style>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<script type="text/javascript">

</script>
<div>
<telerik:RadComboBox runat="server" ID="RadComboBox1" AutoPostBack="true" CheckBoxes="true"
EnableCheckAllItemsCheckBox="true"
Localization-CheckAllString="(All)"
EmptyMessage="Select"
CheckedItemsTexts="FitInInput"
Filter="StartsWith"
DropDownWidth="300px"
MaxHeight="400px"
Width="130px"
Sort="Ascending"
DataTextField="Text"
DataValueField="Value"
DataSourceID="XmlDataSource1" />

<telerik:RadComboBox runat="server" ID="RadComboBox2" AutoPostBack="true" OnTextChanged="RadComboBox2_TextChanged" CheckBoxes="true"
EnableCheckAllItemsCheckBox="true"
Localization-CheckAllString="(All)"
EmptyMessage="Select"
CheckedItemsTexts="FitInInput"
Filter="StartsWith"
DropDownWidth="210px"
MaxHeight="400px"
Width="130px"
Sort="Ascending"
DataTextField="Text"
DataValueField="Value"
DataSourceID="XmlDataSource1" />

<asp:XmlDataSource runat="server" ID="XmlDataSource1" DataFile="~/App_Data/cities.xml" />
<telerik:RadButton runat="server" ID="Button1" Text="Search" OnClick="Button1_Click" AutoPostBack="true" UseSubmitBehavior="false" Width="80px" />

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="Button1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadComboBox2" />
<telerik:AjaxUpdatedControl ControlID="RadComboBox1" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadComboBox2">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadComboBox1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
</div>
</form>
</body>
</html>

0
Nina
Top achievements
Rank 1
answered on 12 Mar 2015, 03:54 PM
To reproduce the issue, just open the page and click the search button. First event being called is the RadComboBox2_TextChanged event.

In version 2014Q1 everything was working as expected and event not being called. It seems to me it has to do with the FitInInput attribute. When it is not set, everything is working fine. But we need this attribute. Any help is appreciated.
0
Ivan Danchev
Telerik team
answered on 17 Mar 2015, 10:47 AM
Hello,

Thank you for the explanation.

We managed to reproduce the behavior you are describing. The RadComboBox's TextChanged event fires because the text in the RadComboBox's input area changes when you check items in the SetStandardFilter method.

Please, find linked the TextChanged documentation article, which gives more details on the conditions under which this event is fired.

Regards,
Ivan Danchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ComboBox
Asked by
Nina
Top achievements
Rank 1
Answers by
Nina
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or