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

ComboBox not always fired

1 Answer 52 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Cecilie Nordbø
Top achievements
Rank 1
Cecilie Nordbø asked on 31 Mar 2011, 12:36 PM
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>                                                                                                         

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 06 Apr 2011, 09:14 AM
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
Tags
ComboBox
Asked by
Cecilie Nordbø
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or