Can you use findcontrol with an Ajax Accordion in

2019-08-03 17:40发布

This goes along with another question that I have asked, I have a drop down list on my master page that causes postback when changed and in that index changed method I am trying to find my ajax accordion to look at the selected index of it

protected void ddlSelectedCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
    CustomerSelected();

    Response.AppendHeader("Refresh", "0;URL=storefront.aspx");

    ViewState["SelectedAccordionIndex"] = (AjaxControlToolkit.Accordion)FindControl("MyAccordion").SelectedIndex;
}

Error that I get

Object reference not set to an instance of an object.

2条回答
我想做一个坏孩纸
2楼-- · 2019-08-03 18:19

the problem is FindControl returns an Object. Cast it to an accordion and try again: ViewState["SelectedAccordionIndex"] = ((Accordion)FindControl("MyAccordion")).SelectedIndex;

If this doesn't why you may need to drill deeper, e.g. ((Accordion)this.FindControl(<the id of your content placeholder your accordion is in>).FindControl("MyAccordion")).SelectedIndex;

查看更多
老娘就宠你
3楼-- · 2019-08-03 18:22

You should be able to use it the same as with any other ASP control. As mentioned above, it returns as an Object so you will have to cast it as any control you are using, whether it be a dropdown, a listbox, or in this case an ajax accordion

查看更多
登录 后发表回答