Can you use findcontrol with an Ajax Accordion in c#?

你说的曾经没有我的故事 提交于 2019-12-11 07:55:01

问题


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.


回答1:


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;




回答2:


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



来源:https://stackoverflow.com/questions/10555804/can-you-use-findcontrol-with-an-ajax-accordion-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!