I have created a custom user control that is meant to extend the functionality of the GridView. It inherits from UserControl and implements IPostBackEventHandler.
The problem I’m having is that the IPostBackEventHandler.RaisePostBackEvent function SOMETIMES does not get called by the framework. I have placed this control on several pages, and on some pages it works fine, and on some pages it does not. I have checked Request[“__EVENTTARGET”] and verified that it is equal to the UniqueID of the control, but RaisePostBackEvent still does not get called.
Is anyone aware of a reason why RaisePostBackEvent might not get called?
Here is the code for my user control:
namespace Warrior.PL.Controls
{
/// <summary>
/// A GridView that supports filter fields at the top of each column.
/// </summary>
[ParseChildren(ChildrenAsProperties = true)]
[ToolboxData("<{0}:FilterableGridView runat=\"server\"></{0}:FilterableGridView>")]
public partial class FilterableGridView : UserControl, IPostBackEventHandler
{
...
#region IPostBackEventHandler Members
void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
{
if (eventArgument != null && eventArgument.StartsWith("Filter"))
{
OnFiltering(new GridViewFilterEventArgs()); // This is a function that I created
}
}
#endregion
...
}
}
Here is the implementation of the control on one of the pages that works:
<warrior:FilterableGridView ID="gvItemCert" runat="server" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" CellPadding="4" CssClass="GridView"
OnPageIndexChanging="gvItemCert_PageIndexChanging" OnRowDataBound="gvItemCert_RowDataBound" OnSorting="gvItemCert_Sorting" OnFiltering="gvItemCert_Filtering" PageSize="100">
...
</warrior:FilterableGridView>
And here is the implementation on a page where it does not work:
<warrior:FilterableGridView ID="gvEquipSN" runat="server" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false" CellPadding="4" CssClass="GridView" EnableViewState="false"
OnPageIndexChanging="gvEquipSN_PageIndexChanging" OnRowDataBound="gvEquipSN_RowDataBound" OnSorting="gvEquipSN_Sorting" OnFiltering="gvEquipSN_Filtering" PageSize="20">
...
</warrior:FilterableGridView>
The only difference I see is that the one that does not work has EnableViewState=”false”. I have ruled this out as being the problem, though, as setting EnableViewState=”true” does not help anything.
Also, I am using AJAX on both pages.
It turns out that the previous solution does not work if there are two of these controls on the same page because apparently only ONE control on the page is allowed to call Page.RegisterRequiresRaiseEvent. Furthermore, if a control calls Page.RegisterRequiresRaiseEvent, then none of the other controls on the page get their RaisePostBackEvent function called.
In fact, this was my whole problem: I had another control on the page that called Page.RegisterRequiresRaiseEvent, so my FilterableGridView never got its RaisePostBackEvent function called!
I knew there had to be something else going on underneath all of this…