您可以在C#中将findcontrol与Ajax手风琴一起使用吗? [英] Can you use findcontrol with an Ajax Accordion in c#?

查看:89
本文介绍了您可以在C#中将findcontrol与Ajax手风琴一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这伴随着我所问的另一个问题,我的主页上有一个下拉列表,该下拉列表在更改时导致回发,并且在该索引更改方法中,我试图找到我的Ajax手风琴来查看选定的索引

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;
}

我得到的错误

对象引用未设置为对象的实例。

Object reference not set to an instance of an object.

推荐答案

问题是FindControl返回对象。将其转换为手风琴,然后重试: ViewState [ SelectedAccordionIndex] =(((Accordion)FindControl( MyAccordion))。SelectedIndex;

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

如果这不是为什么,您可能需要更深入地研究,例如(((Accordion)this.FindControl(<您的手风琴所在的内容占位符的ID)>)。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;

这篇关于您可以在C#中将findcontrol与Ajax手风琴一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆