从另一个用户控制的控制更新的用户控件更新面板 [英] Updating an Update Panel in a usercontrol from a control in another user control

查看:150
本文介绍了从另一个用户控制的控制更新的用户控件更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一起来,对于这个问题的长度的歉意!

First up, apologies for the length of this question!

我有两个是相互依存的有些对他们几个的Web用户控件的页面。在一个理想的世界里,他们可以是一个控制,但由于种种原因,他们需要有两个。

I have a page with several web user controls on them two of which are somewhat interdependent. In an ideal world they could be one control but for various reasons they need to be two.

我需要在基于在另一个控制DropDownList的动作的控制中的一个来更新更新面板,如下所述。

I need to update an update panel in one of the controls based on the action of a dropdownlist in another control, as described below.

为此,我们将调用控件的 JobControl作业控制呼叫控制。 JobControl作业控制包含一个下拉列表,这是从AJAXControlToolkit级联下拉列表中的一部分。当此下拉有选择的指数的变化我想更新呼叫控制的控制面板。

For this purpose we will call the controls JobControl and CallControl. JobControl contains a dropdown list, which is part of a Cascading Dropdown list from the AJAXControlToolkit. When this dropdown has a selected index change I want to update the control panel in CallControl.

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

CallControl exposes it's update panel as such:

    public UpdatePanel UpdatePanel
    {
        get { return updCall; }
    }

JobControl作业控制有一个公共的成员 AssociatedCallControl

private ServiceCallControl associatedCallControl;

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

两个随后在含有控制页面的onLoad事件相关联在一起。

The two are then associated together in the OnLoad event of the page containing the controls.

这SO问题:<一href=\"http://stackoverflow.com/questions/2542469/update-panel-error-control-with-the-id-xxx-could-not-be-found-in-the-updatepa\">Update面板错误:与ID&QUOT控制; XXX&QUOT;

This SO Question: Update Panel error: Control with the ID "xxx" could not be found in the UpdatePanel led me to try this in the onload event of the JobControl:

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作业控制

With the following also added to the JobControl

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

哈弗这一切后我仍然得到 ID为TabContainer1_tabJob_ctrlJob_ddCallGroup的控制不能在UpdatePanel的'updCall触发找到。

我是不是与虎谋皮?我要对这个错误的方式或者已经我只是错过了什么?

Am I attempting the impossible? Am I going about this the wrong way or have I just missed something?

推荐答案

试试这个,
- 创建和调用的呼叫控制一个EventHandler委托;
- 它指向当前页面的方法;
- 在该方法中,调用简单地

Try this if u can, - Create and Invoke a EventHandler delegate in the CallControl; - Point it to a method in current Page; - In this method, call simply

JobCtrl.UpdatePanel.Update();

JobCtrl.UpdatePanel.Update();

希望这有助于!

编辑:code例如

CallControl.ascx.cs:

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:

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

Page.aspx.cs:

Page.aspx.cs:

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

希望这是明确的..!

Hope this is clear..!

这篇关于从另一个用户控制的控制更新的用户控件更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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