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



首先,很抱歉这个问题太长了!

我有一个页面,上面有几个web用户控件,其中两个控件在某种程度上是相互依赖的。在一个理想的世界里,它们可以是一个控件,但由于各种原因,它们必须是两个控件。

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

为此,我们将调用控件JobControl

CallControlCallControl将其更新面板公开为:

public UpdatePanel UpdatePanel
{
get { return updCall; }
}

JobControl有一个公共成员AssociatedCallControl

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

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

此SO问题:更新面板错误:ID为"的控件;xxx";在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'.

我在尝试不可能的事情吗?我是走错了路还是错过了什么?

如果可以的话,试试这个,-在CallControl中创建并调用EventHandler委托;-将其指向当前页面中的一个方法;-在这个方法中,只调用

JobCtrl.UpdatePanel.Update();

希望得到帮助!

EDIT:代码示例

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

希望这是清楚的。。!

最新更新