Updating an Update Panel in a usercontrol from a c

2019-06-13 05:38发布

First up, apologies for the length of this question!

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.

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.

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 has a public member AssociatedCallControl

private ServiceCallControl associatedCallControl;

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

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

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

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

Hover after all this I still get A control with ID 'TabContainer1_tabJob_ctrlJob_ddCallGroup' could not be found for the trigger in UpdatePanel 'updCall'.

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

1条回答
放我归山
2楼-- · 2019-06-13 06:37

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

Hope this help!

EDIT: code example

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

Hope this is clear..!

查看更多
登录 后发表回答