1

I have a gridview that's inside a .ascx control that's dynamically embedded into another .ascx control, which is then called by a web form. The gridview will initially bind, but when any paging/sorting/command events are then triggered, I can't get any breakpoints inside the events to kick off. Additionally, when I look at the code-behind in the now-blank page, I see the old data sitting there.

Any idea what on earth is going on here? For edification, the .ascx page with the control is excerpted.

Parent .ascx control:

<asp:ScriptManager ID="smIndex" runat="server" EnablePartialRendering="true" EnableScriptLocalization="true" EnableScriptGlobalization="true" />

Child .ascx control:

<asp:UpdatePanel ID="upAddAdj" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
    <asp:GridView ID="gvAddAdjVenList" runat="server" AllowPaging="true" AllowSorting="true" Width="100%" AutoGenerateColumns="false" Font-Size="9px" Font-Names="Verdana" PageSize="10" EnableSortingAndPagingCallbacks="false" DataKeyNames="ID" PagerSettings-Mode="NumericFirstLast" OnRowDataBound="gvAddAdjVenList_RowDataBound" Visible="true">

In the child.ascx code-behind:

gvAddAdjVenList.DataBind();
gvAddAdjVenList.Sorting += new GridViewSortEventHandler(gvAddAdjVenList_Sorting);
gvAddAdjVenList.PageIndexChanging += new GridViewPageEventHandler(gvAddAdjVenList_PageIndexChanging);

Thanks!

valkyrie

Valkyrie
  • 11,655
  • 2
  • 20
  • 17

1 Answers1

0

If you are 'dynamically embedding' the child control into another control from C#, ensure that you are assigning an ID to the child control:

gvAddAdjVenList.DataBind();      
gvAddAdjVenList.Sorting += new GridViewSortEventHandler(gvAddAdjVenList_Sorting);      
gvAddAdjVenList.PageIndexChanging += new GridViewPageEventHandler(gvAddAdjVenList_PageIndexChanging); 

gvAddAdjVenList.ID = "gvAddAdjVenList"; // Make sure you do this
parentControl.Controls.Add(gvAddAdjVenList);

to ensure that its events can be wired up correctly.

This was previously discovered here.

Community
  • 1
  • 1
kevev22
  • 3,737
  • 21
  • 32
  • I've assigned an ID to the controls that are embedded, but I don't see a difference in behavior. None of the controls that are within the child .ascx are dynamically generated, so I'm not sure how to assign an ID other than in the tag's attribute. – Valkyrie Nov 08 '10 at 13:37
  • If it helps, here's how I'm attaching the .ascx controls to the placeholder control: Control ctrlAddAdj = LoadControl("AddAdjustments.ascx"); ctrlAddAdj.ID = "ucAddAdj"; phControl.Controls.Clear(); phControl.Controls.Add(ctrlAddAdj); – Valkyrie Nov 08 '10 at 13:53
  • I've also tried to attach the .ascx controls directly to a placeholder that's on a .aspx page instead of a parent .ascx page and I still see the same behavior. – Valkyrie Nov 08 '10 at 13:54