![](/img/trans.png)
[英]updating a user control in an asp.net update panel (based upon action in another user control)
[英]Updating an Update Panel in a usercontrol from a control in another user control
首先,对这个问题的长度道歉!
我有一个页面上有几个Web用户控件,其中两个有点相互依赖。 在一个理想的世界中,他们可能是一个控制,但由于各种原因,他们需要两个。
我需要根据另一个控件中下拉列表的操作更新其中一个控件中的更新面板,如下所述。
为此,我们将调用控件JobControl和CallControl 。 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));
}
在所有这些之后悬停我仍然得到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:
<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();
}
}
希望这很清楚..!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.