2012-10-16 36 views
0

首先,对此问题的长度表示歉意!在另一个用户控件中的控件中更新usercontrol中的更新面板

我有一个页面上有几个网页用户控件,其中两个有些相互依赖。在理想的世界里,他们可以成为一个控制者,但由于各种原因他们需要两个控制者。

我需要根据另一个控件中的下拉列表的操作更新其中一个控件的更新面板,如下所述。

为此,我们将调用控件JobControlCallControl。 JobControl包含一个下拉列表,该列表是AJAXControlToolkit的级联下拉列表的一部分。当此下拉列表中选择了索引更改时,我想更新CallControl中的控制面板。

呼叫控制暴露它的更新面板作为这样:

public UpdatePanel UpdatePanel 
    { 
     get { return updCall; } 
    } 

JobControl作业控制有一个公共的构件AssociatedCallControl

private ServiceCallControl associatedCallControl; 

public ServiceCallControl AssociatedCallControl 
{ 
    get { return associatedCallControl; } 
    set { associatedCallControl = value; } 
} 

在包含控制页面的onLoad事件两个然后结合在一起。

这太问题:Update Panel error: Control with the ID "xxx" could not be found in the UpdatePanel促使我尝试这种在JobControl作业控制的onload事件:

if (associatedCallControl != null) 
{ 
    AsyncPostBackTrigger trig = new AsyncPostBackTrigger(); 
    string s = ddCallGroup.ClientID; 
    //ddCallGroup is the dropdown I want to trigger the update of the CallControl 
    trig.ControlID = ddCallGroup.ClientID; //Also Tried ddCallGroup.ID 
    trig.EventName = "CallGroupChanged"; 
    associatedCallControl.UpdatePanel.Triggers.Add(trig); 
} 

有以下也加入到JobControl作业控制

public void CallGroupChanged(object sender, EventArgs e) 
{ 
    //Stuff to update the CallControl panel including calling update(); 
    associatedCallControl.RefreshMehods(int.Parse(ddCallGroup.SelectedValue));   
} 

哈弗这一切后我仍然得到A control with ID 'TabContainer1_tabJob_ctrlJob_ddCallGroup' could not be found for the trigger in UpdatePanel 'updCall'.

我想试试这个不可能的东西吗?我是以这种错误的方式去做的,还是我错过了什么?

回答

2

如果可以,请尝试此操作, - 在CallControl中创建并调用EventHandler委托; - 将它指向当前页面中的方法; - 在此方法中,只需致电

JobCtrl.UpdatePanel.Update();

希望得到这个帮助!

编辑:代码示例

CallControl.ascx.cs:

public partial class JobControl 
{ 
    public void CallGroupChanged(object sender, EventArgs e) 
    { 
     // do your work 

     if (this.MyEventDelegate != null) // check if the event is not null 
      this.MyEventDelegate(this, null); // invoke it 
    } 

    public event EventHandler MyEventDelegate; 
} 

Page.aspx:

<controls:CallControl runat="server" ID="CallControl1" OnMyEventDelegate="RefreshMethod" /> 

Page.aspx.cs:

public partial class Page_aspx : System.Web.UI.Page 
{ 
    protected void RefreshMethod(object sender, EventArgs e) 
    { 
     this.CallControl1.UpdatePanel.Update(); 
    } 
} 

希望这很清楚..!

+0

您可以添加创建和调用事件处理程序委托的示例。此外,这实际上会在JobControl中,因为这是我想用作触发器的下拉列表。更新面板在CallControl中?另外,如果可能的话,我想尝试在控件中保留这些方法。感谢你目前的帮助。 –

+0

我刚刚编辑帖子!告诉我,如果不清楚 –

+0

我编辑了你的答案,以更改包含更新到CallControl的控件。实际上,我在上面的代码中混淆了其他领域的其他发现,所以我将发布完整的解决方案作为答案。但很多非常感谢您的帮助。 –

相关问题