Connected Visual Webpart - RegisterAsyncPostBackControl is not working?
-
11-01-2021 - |
Domanda
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");
}
}
Soluzione
Credit goes to @KenHansen, Updated the code as below and it works
<td>
<asp:UpdatePanel ID="btApplyFilterPanel" runat="server">
<ContentTemplate>
<asp:Button ID="btApplyFilter" OnClick="btApplyFilter_Click" runat="server" Text="Apply Filter" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btApplyFilter" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
<td>
<asp:UpdatePanel ID="btClearFilterPanel" runat="server">
<ContentTemplate>
<asp:Button ID="btClearFilter" OnClick="btClearFilter_Click" runat="server" Text="Clear Filter" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btClearFilter" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
Altri suggerimenti
I guess I should have posted as an answer rather than a comment in order to claim the bounty...
Thank you. I see that the button calls btApplyFilter_Click, but I don't see what that does. It could be that the click itself it causing a pageload rather than a data refresh.