从另一个用户控件中的控件更新用户控件中的更新面板

首先,对这个问题的长度道歉!

我有一个页面上有几个Web用户控件,其中两个有点相互依赖。 在一个理想的世界中,他们可能是一个控制,但由于各种原因,他们需要两个。

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

为此,我们将调用控件JobControlCallControl 。 JobControl包含一个下拉列表,它是AJAXControlToolkit的Cascading Dropdown列表的一部分。 当此下拉列表具有选定的索引更改时,我想更新CallControl中的控制面板。

CallControl公开了它的更新面板:

public UpdatePanel UpdatePanel { get { return updCall; } } 

JobControl有一个公共成员AssociatedCallControl

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

然后,这两个在包含控件的页面的OnLoad事件中关联在一起。

这个SO问题: 更新面板错误:在UpdatePanel中找不到ID为“xxx”的控件,导致我在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)); } 

在所有这些之后hover我仍然得到A control with ID 'TabContainer1_tabJob_ctrlJob_ddCallGroup' could not be found for the trigger in UpdatePanel 'updCall'.

我尝试不可能吗? 我是以错误的方式解决这个问题还是我错过了什么?

如果你可以尝试这个, – 在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:

  

Page.aspx.cs:

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

希望这很清楚..!