How can I get an UpdatePanel to intercept a CompositeControl DropDownList

I have a CompositeControl that contains a DropDownList.

I set the AutoPostBack property for DropDownList to true.

On the page I have:

<asp:UpdatePanel ID="UpdatePanel" runat="server">
    <ContentTemplate>
        <MyControl:Control ID="CustomControl" runat="server" />
    </ContentTemplate>
</asp:UpdatePanel>

I also tried setting ChildrenAsTriggers = "true" and UpdateMode = "Always" , but did not solve the problem.

The problem is that the UpdatePanel does not intercept the CompositeControl DropDownList message. (The full version of POST is executed when DropDownList changes)

How can I get an UpdatePanel to handle postback?

Thanks!

Edit - requested information

Country and states are DropDownLists lists in CompositeControl.

country.SelectedIndexChanged += new EventHandler(country_SelectedIndexChanged);

protected void country_SelectedIndexChanged(Object sender, EventArgs e)
{
    states.DataSource = XXX;
    states.DataBind();
}
+1
4

, , , , UpdatePanel . - . , (CatchMyEvent, , , ), DropDownList. , SelectedIndexChanged SelectedItem.Text. , . , :

public partial class CatchMyEvent : System.Web.UI.UserControl
{
    public delegate void ChangedIndex(object sender, EventArgs e);
    public event ChangedIndex SelectedIndexChanged;

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        dropDownListThrow.SelectedIndexChanged += new EventHandler(dropDownListThrow_SelectedIndexChanged);
        labelOutput.Text = "no";
    }

    public void dropDownListThrow_SelectedIndexChanged(object sender, EventArgs e)
    {
        labelOutput.Text = ((DropDownList)sender).SelectedItem.Text;
        if(SelectedIndexChanged != null)
        {
            SelectedIndexChanged(sender, e);
        }
    }
}

, , - DropDownList SelectedIndexChanged , . , , , . .

UpdatePanel , :

<asp:AsyncPostBackTrigger ControlID="catchMyEventMain" EventName="SelectedIndexChanged" />

... , , :

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    catchMyEventMain.SelectedIndexChanged += dropDownListThrow_SelectedIndexChanged;
}

public void dropDownListThrow_SelectedIndexChanged(object sender, EventArgs e)
{        
    labelSelectedValue.Text = ((DropDownList)sender).SelectedItem.Text;
}

. .

:

1) , , AutoPostBack DropDownList true.

2) , UpdatePanel ContentTemplate.

, .

+3

( ) ListView UpdatePanel.

() .

PAGE ( .aspx): ClientIDMode = "AutoID"

, UpdatePanel - .

+2

BuildControlHierarchy:

        ...
        if (DesignMode || Page == null) return;

        var sm = ScriptManager.GetCurrent(Page);
        if (sm == null)
        {
            throw new MissingFieldException("The ScriptManager is needed on the page!");
        }
        sm.RegisterAsyncPostBackControl(<control which initiates async postback>);
0

, .

. .

0

Source: https://habr.com/ru/post/1704302/


All Articles