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

Executing OnInit on selectedIndexchanged of radcombo

1 Answer 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Balaji
Top achievements
Rank 1
Balaji asked on 22 Aug 2011, 11:15 AM
Hi,

I am trying to load my second combobox based on the item selected from first combobox. The code goes something like this

Aspx page

<telerik:RadComboBox ID="DepartmentDD" runat="server" OnItemsRequested="DepartmentDD_ItemsRequested" OnClientSelectedIndexChanging="LoadSection" OnClientItemsRequested="ItemsLoaded" width="175px"/>


<telerik:RadComboBox ID="SectionDD" runat="server" OnItemsRequested="SectionDD_ItemsRequested" OnClientItemsRequested="ItemsLoaded" width="175px" />   


function ItemsLoaded(combo, eventarqs) {

    var secCombo = $find("SectionDD");
    if (combo.get_items().get_count() > 0) {
        combo.set_text(combo.get_items().getItem(0).get_text());
        combo.get_items().getItem(0).highlight();
    }
                    combo.showDropDown();
}


function LoadSection(combo, eventarqs) {
    var seccombo = $find("SectionDD");
    var item = eventarqs.get_item();

    seccombo .set_text("Loading...");
    seccombo .requestItems(item.get_value(), false);
}


---------

CS page


 protected void Page_Load(object sender, EventArgs e)
{

    LoadDepartment();

}
      

    protected void LoadDepartment()
        {
        //Loads department to DepartmentDD
        }


        protected void DepartmentDD_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadDepartment();
        }

        protected void SectionDD_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {

            LoadSection(Convert.ToInt16(deptid));
        }

        protected void LoadSection(int deptId)
        {
            
          //Loads section to SectionDD
        }


The problem is when I reach SectionDD_ItemsRequested after selecting item from first combo the control is firing OnInit method which loads the deparment againg :(.

Where am I going wrong?

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 24 Aug 2011, 09:30 AM
Hello Balaji,

You should place your LoadDepartment method inside the following conditional statement:
if (!Page.IsPostBack)
           {
 
               LoadDepartament();   
           }

Please refer to the following demo implementing the same scenario.

Greetings,
Dimitar Terziev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Balaji
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or