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

SelectedIndexChanged Not Firing on First Time

1 Answer 271 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Shahzad Ilyas
Top achievements
Rank 2
Shahzad Ilyas asked on 18 Oct 2011, 05:38 PM

HI

OnSelectedIndexChanged Issue:

when user selects the index value from radcombobox its does not fire OnSelectedIndexChanged for frist time.
acutally it does not fire afterwords until some other controls his postback
then radcombobox OnSelectedIndexChanged get fire first and then other control's  event.


ASPX
<form id="form1" runat="server" method="post"
 <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
  </telerik:RadScriptManager
<div>
 <telerik:RadComboBox ID="rcbResource" runat="server" Height="200px" Width="230px"                                     AutoPostBack="true" DropDownWidth="500px" EmptyMessage="Search a Text" HighlightTemplatedItems="true"
  
EnableLoadOnDemand="true"  Filter="Contains"  OnItemsRequested="rcbResource_ItemsRequested" OnSelectedIndexChanged="rcbResource_SelectedIndexChanged"  MarkFirstMatch="true" EnablePostBackOnRowClick="true" >
    <HeaderTemplate>
      <table cellspacing="0" cellpadding="0">
        <tr>
          <td style="font-size: 12px; width: 150px; word-wrap: break-word;">
            Key
          </td>
          <td style="font-size: 12px; padding-left: 10px">
             Text
          </td>
        </tr>
      </table>
    </HeaderTemplate>
    <ItemTemplate>
    <table width="100%" cellspacing="0" cellpadding="0" style="border: 1px solid grey">
     <tr>
      <td class="menuoff" onmouseover="className='menuon';" onmouseout="className='menuoff';">
          <%# DataBinder.Eval(Container, "Text")%>
      </td>
  
      <td style="text-align: left;">
       <%# DataBinder.Eval(Container, "Attributes['Text']")%>
     </td>
     </tr>
    </table>
    </ItemTemplate>
  </telerik:RadComboBox>
</div>  
</form>


C# ASP.NET

 

protected void rcbResource_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
 {
    if (e.Text != "")
    {
       var SearchList = DataManager.SearchResourceText(e.Text.Trim());
             foreach (var resource in SearchList)
             {
                 RadComboBoxItem item = new RadComboBoxItem();
                 //set the key
                 item.Text = resource.mkFieldId;
                 item.Value = resource.mkDictionaryId.ToString();
                 string text = resource.Text;
                 item.Attributes.Add("Text", text);
                 rcbResource.Items.Add(item);
                 item.DataBind();
              }
  
         }
  
         else
         {
             RadComboBoxItem item = new RadComboBoxItem();
             item.Text = "No Key Found";
             item.Value = "1";
             string text = "Enter a text";
             item.Attributes.Add("Text", text);
             rcbResource.Items.Add(item);
             item.DataBind();
         }
   }     
 
  
  
protected void rcbResource_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
  
        if (lstResourceIds.Items.FindByText(e.Text) != null)
        {
             lstResourceIds.SelectedValue = lstResourceIds.Items.FindByText(e.Text).Value;
            rcbResource.Text = "";
  
        }                          
 
    }

 

 
please advise if im missing something.
regards
Shaz

 

 

1 Answer, 1 is accepted

Sort by
0
Shahzad Ilyas
Top achievements
Rank 2
answered on 19 Oct 2011, 02:26 PM
Hi
found the solution thanks to Shinu..:D

Quote "One suggestion would be invoking postback from client side SelectionIndexChanged event of RadComboBox instead of setting the AutoPostBack property to True. Give a try with the following code."


ASPX
<telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="false" AllowCustomText="True" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"
OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1">
</telerik:RadComboBoxItem>
</Items>
</telerik:RadComboBox>


JavaScript
<script type="text/javascript">
function OnClientSelectedIndexChanged(sender, args)
{
__doPostBack('RadComboBox1','');
}
</script>

thank you so much
regards
Shaz
Tags
ComboBox
Asked by
Shahzad Ilyas
Top achievements
Rank 2
Answers by
Shahzad Ilyas
Top achievements
Rank 2
Share this question
or