#StackBounty: #ajax #connected-web-parts #updatepanel Connected Visual Webpart – RegisterAsyncPostBackControl is not working?

Bounty: 100

I have two visual webparts connected. Provider webpart has user control (button) that should trigger update on the Consumer webpart.

I do see that RegisterAsyncPostBackControl is called and control is registered in the consumer webpart. However, still the page gets reload.

Consumer webpart has update panel that holds the SPGridView control, I want to refresh the data on the SPGridView based on the button clicked on the Provider webpart.

What I am missing.

namespace Demo.VisualWebParts.MediaCenterListView
{
    [ToolboxItemAttribute(false)]
    public class MediaCenterListView : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/15/Demo.VisualWebParts/MediaCenterListView/MediaCenterListViewUserControl.ascx";
        protected IListFilterString _provider;

        [Personalizable(PersonalizationScope.Shared)]
        [WebBrowsable(true)]
        [WebDisplayName("List Name")]
        [Category("Custom")]
        public string ListName { get; set; }

        public string ListFilter { get; set; }

        public MediaCenterListView()
        {
            if (this.ListName == null)
            {
                this.ListName = GlobalConstant.LIST_MEDIAIMAGE;
            }

            if(ListFilter ==null)
            {
                ListFilter = string.Empty;
            }
        }

        protected override void CreateChildControls()
        {
            var control = Page.LoadControl(_ascxPath) as MediaCenterListViewUserControl;
            control.ConnectWebPart(this);
            Controls.Add(control);
        }

        [ConnectionConsumer("List Filter")]
        public void RegisterListFilterProvider(IListFilterString provider)
        {
            _provider = provider;

            if (_provider != null)
            {
                if (!string.IsNullOrEmpty(_provider.ListFilterString))
                {
                    this.ListFilter = _provider.ListFilterString;
                }

                if (!string.IsNullOrEmpty(_provider.ListNameString))
                {
                    this.ListName = _provider.ListNameString;
                }
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnLoad(e);

            if (_provider != null && _provider.TriggerControl != null)
            {
                var smgr = ScriptManager.GetCurrent(this.Page);
                smgr.RegisterAsyncPostBackControl(_provider.TriggerControl);
            }
        }
    }
}

Updated: 02/27/2018
Provider User Control

<table>
    <tr>
        <td>Tags
        </td>
        <td>
            <Taxonomy:TaxonomyWebTaggingControl runat="server" ID="MediaTaxonomyWebTaggingControl"
                Visible="true"
                IsUseCommaAsDelimiter="true"
                IsSpanTermSets="true"
                IsSpanTermStores="false"
                IsDisplayPickerButton="true"
                IsMulti="true"
                AllowFillIn="true"
                IsAddTerms="false"
                IsIncludePathData="false">
            </Taxonomy:TaxonomyWebTaggingControl>
        </td>
    </tr>
    <tr>
        <td>Category
        </td>
        <td>
            <asp:DropDownList ID="ImageCategory" runat="server" AutoPostBack="false" Width="241px">
                <asp:ListItem Enabled="true" Text="Select Category" Value="-1"></asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td>File Name
        </td>
        <td>
            <asp:TextBox ID="FileLeafRef" autocomplete="off" MaxLength="100" runat="server" Width="229px"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Button ID="btApplyFilter" OnClick="btApplyFilter_Click" runat="server" Text="Apply Filter" />
        </td>
        <td>
            <asp:Button ID="btClearFilter" OnClick="btClearFilter_Click" runat="server" Text="Clear Filter" />
        </td>
    </tr>
</table>

Interface

public interface IListFilterString
{
    string ListNameString { get; }
    string ListFilterString { get; }
    Control TriggerControl { get; }
}

Provider Implementation of IListFilterString interface

   public Control TriggerControl
    {
        get
        {
            return (Page.LoadControl(_ascxPath) as MediaCenterListFilterUserControl).FindControl("btApplyFilter");
        }
    }


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.