ComboBox not always fired

2 posts, 0 answers
  1. Cecilie Nordbø
    Cecilie Nordbø avatar
    34 posts
    Member since:
    Feb 2010

    Posted 31 Mar 2011 Link to this post

    Hi.
    I have a grid with a comboBox that use the event SelectedIndexChanged. AutoPostBack is set to true. The problem is that the event handler does not fired every time the comboBox index changed (in insert-mode), nearly never. When the index changed and it has not fired and i fill in values in some RadTextBox, then it fired when i save the new record. (I have also tried to use the OnTextChanged event and same happens here.)  The comboBox contain a list of companies and i use LinqDataSoure to get the companies.

    Here is the code i am using and the  comboBox that not work correctly is with the id= Company :

    protected void CompanyComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
          {         
              var combo = (RadComboBox) sender;
              if (combo == null)
                  return;
               
              var item = combo.NamingContainer is GridEditFormInsertItem ? (GridEditFormInsertItem)combo.NamingContainer : (GridEditFormItem)combo.NamingContainer;           
              var userNumberBox = (RadNumericTextBox)item.FindControl("UserNumber");
     
              string userNumber = userNumberBox.Text;
              string companyId = combo.SelectedValue;
     
              if (string.IsNullOrEmpty(userNumber) || string.IsNullOrEmpty(companyId))
                  return;
     
              var firstNameBox = (RadTextBox)item.FindControl("FirstName");
              var lastNameBox = (RadTextBox)item.FindControl("lastName");
     
              User user = GetUser(userNumber, companyId);
              if (user != null)
              {
                  firstNameBox.Text = user.FirstName;
                  lastNameBox.Text = user.LastName;
              }
              else
              {
                  firstNameBox.Text = string.Empty;
                  lastNameBox.Text = string.Empty;
              }
          }

    <EditFormSettings EditFormType="Template">
               <EditColumn UniqueName="EditCommandColumn1" ></EditColumn>
              <FormTemplate>                
                        <div id="column1" style="float:left;padding:10px;">
                            <div style="padding-bottom:7px;">
                                <table>                     
                                    <tr><td><asp:Label ID="NumberLabel" runat="server" Text="Brukernr.:"></asp:Label></td><td><telerik:RadNumericTextBox runat="server" OnTextChanged="UserNumberTextBox_TextChanged" AutoPostBack="true" ID="UserNumber" Width="107" DataType="System.Int32"><NumberFormat DecimalDigits="0" GroupSeparator=""/></telerik:RadNumericTextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" Text="*" ForeColor="Red" ControlToValidate="UserNumber" runat="server"/>
                                    <asp:Label ID="Label21" runat="server" Text="Aktiv"></asp:Label>
                                    <telerik:RadComboBox runat="server" ID="RadComboBoxActive" Width="45px" DataValueField="IsActive" AutoPostBack="true">
                                        <Items>                             
                                            <telerik:RadComboBoxItem Value="1" Text="Ja"/>
                                            <telerik:RadComboBoxItem Value="0" Text="Nei"/>
                                        </Items>
                                    </telerik:RadComboBox></td></tr>
                                   <tr><td><asp:Label ID="CompanyLabel" runat="server" Text="Selskap/Avd.:"></asp:Label></td>
                                                   <
    td colspan="2"><telerik:RadComboBox  ID="Company" runat="server" OnSelectedIndexChanged="CompanyComboBox_SelectedIndexChanged" CausesValidation="true" AutoPostBack="true"   DataSourceID="CompanyDataSource"  DataTextField="Name" DataValueField="CompanyId"  EmptyMessage="Velg et element" AllowCustomText="true"></telerik:RadComboBox>
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Text="*" ForeColor="Red" ControlToValidate="Company" runat="server"/></td></tr>                                                                                               
                                </table>
                            </div>
                         </div>
                         <div id="column1b" style="float:left;padding:10px;">
                            <div style="padding-bottom:7px;">
                                <table>                    
                                    <tr><td><asp:Label ID="FirstNameLabel"  runat="server" Text="Fornavn:"></asp:Label></td><td><telerik:RadTextBox ID="FirstName"  runat="server"  Width="150" MaxLength="20"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator2" Text="*" ForeColor="Red" ControlToValidate="FirstName" runat="server"/></td></tr>
                                    <tr><td><asp:Label ID="LastNameLabel"   runat="server" Text="Etternavn:"></asp:Label></td><td><telerik:RadTextBox ID="LastName"   runat="server" Width="150" MaxLength="20"></telerik:RadTextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator8" Text="*" ForeColor="Red" ControlToValidate="LastName" runat="server"/></td></tr>                           
                               </table>                   
                            </div>                                                                  
                        </div>                                                                                                         
  2. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 06 Apr 2011 Link to this post

    Hello Cecilie,

    The reason for the SelectedIndexChanged no being fired is the fact that you have a validation which fails when there is no text in your labels and thus the post-back is suppressed.
    This is why the event is fired only when you have text in your labels and the validation is passed.

    Regards,
    Dimitar Terziev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top