RadComboBox TextChanged event fires on button click

7 posts, 0 answers
  1. Nina
    Nina avatar
    7 posts
    Member since:
    Aug 2014

    Posted 09 Mar 2015 Link to this post

    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.
  2. Nina
    Nina avatar
    7 posts
    Member since:
    Aug 2014

    Posted 09 Mar 2015 Link to this post

    My Telerik version is 2015Q1
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    832 posts

    Posted 11 Mar 2015 Link to this post

    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.

     
  5. Nina
    Nina avatar
    7 posts
    Member since:
    Aug 2014

    Posted 12 Mar 2015 in reply to Ivan Danchev Link to this post

    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);
    }
  6. Nina
    Nina avatar
    7 posts
    Member since:
    Aug 2014

    Posted 12 Mar 2015 in reply to Nina Link to this post

    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>

  7. Nina
    Nina avatar
    7 posts
    Member since:
    Aug 2014

    Posted 12 Mar 2015 Link to this post

    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.
  8. Ivan Danchev
    Admin
    Ivan Danchev avatar
    832 posts

    Posted 17 Mar 2015 Link to this post

    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.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017