Ticket Q380696
Visible to All Users

ASPxPopupControl - How to bind ASPxGridView inside popup on demand on first shown

created 13 years ago

Hi , I using popupcontrols with gridviews.
I want to bind the grids only when the popup is shown.
I have tried popupcontrol.load .init and .prerender but they all bind early.
Is there a way to only databind when the popup is actually shown?
thanks
ian

Answers

created 13 years ago

Hello Ian,
You can set the ASPxPopupControl.LoadContentViaCallback property to "OnFirstShow". In this case, ASPxPopupControl will create its client-side content on demand.
>>Is there a way to only databind when the popup is actually shown?
No, there is not. Since ASPxGridView is a part of ASPxPopupControl and the entire ASP.NET page, all these controls go through the entire page life cycle during each round trip to the server.
Please refer to the ASP.NET Page Life Cycle MSDN article for more information.
Thanks,
Mike

    Show previous comments (5)

      Hello Ian,
      I have prepared samples that illustrate possible ways of binding ASPxGridView on demand when the popup is shown for the first time:

      1. ContentCollection:
        - Define ASPxGridView so that it does not have a datasource assigned;
        - Show ASPxPopupControl on the client side;
        - If ASPxPopupControl is shown for the first time, perform a custom popup callback and bind the embedded ASPxGridView control. Do not forget to bind the grid during each next round trip to the server, because the grid has been bound only once.
      JavaScript
      <script type="text/javascript"> var gridIsBound = false; function OnClick(s, e) { pc.Show(); if(!gridIsBound) { pc.PerformCallback('BindGrid'); gridIsBound = true; } } </script>
      ASPx
      <dx:ASPxButton ID="btn" runat="server" AutoPostBack="false" Text="Show Popup"> <ClientSideEvents Click="OnClick" /> </dx:ASPxButton> <div> <dx:ASPxPopupControl ID="popup" runat="server" AutoUpdatePosition="true" CloseAction="CloseButton" ClientInstanceName="pc" PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter" OnWindowCallback="popup_WindowCallback"> <ContentCollection> <dx:PopupControlContentControl runat="server" SupportsDisabledAttribute="True"> <dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" KeyFieldName="CategoryID" OnDataBinding="grid_DataBinding"> <Columns> <dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="0"> <EditFormSettings Visible="False" /> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="CategoryName" ShowInCustomizationForm="True" VisibleIndex="1"> </dx:GridViewDataTextColumn> <dx:GridViewDataTextColumn FieldName="Description" ShowInCustomizationForm="True" VisibleIndex="2"> </dx:GridViewDataTextColumn> </Columns> </dx:ASPxGridView> </dx:PopupControlContentControl> </ContentCollection> </dx:ASPxPopupControl> </div> <asp:AccessDataSource ID="ds" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"> </asp:AccessDataSource>
      C#
      protected void Page_Load(object sender, EventArgs e) { if(Session["BindGrid"] != null) { grid.DataBind(); } } protected void popup_WindowCallback(object source, PopupWindowCallbackArgs e) { ASPxPopupControl popupControl = (ASPxPopupControl)source; switch(e.Parameter) { case "BindGrid": Session["BindGrid"] = true; ASPxGridView gridView = (ASPxGridView)popupControl.FindControl("grid"); gridView.DataBind(); break; default: break; } } protected void grid_DataBinding(object sender, EventArgs e) { ASPxGridView gridView = (ASPxGridView)sender; if(Session["BindGrid"] != null) { gridView.DataSource = ds; } }
      Visual Basic
      Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Session("BindGrid") IsNot Nothing Then grid.DataBind() End If End Sub Protected Sub popup_WindowCallback(ByVal source As Object, ByVal e As PopupWindowCallbackArgs) Dim popupControl As ASPxPopupControl = CType(source, ASPxPopupControl) Select Case e.Parameter Case "BindGrid" Session("BindGrid") = True Dim gridView As ASPxGridView = CType(popupControl.FindControl("grid"), ASPxGridView) gridView.DataBind() Case Else End Select End Sub Protected Sub grid_DataBinding(ByVal sender As Object, ByVal e As EventArgs) Dim gridView As ASPxGridView = CType(sender, ASPxGridView) If Session("BindGrid") IsNot Nothing Then gridView.DataSource = ds End If End Sub
      1. ContentUrl:
        - It is a standalone implementation of the E2270 Code Central example: the ASPxGridView control is part of the external page's hierarchy. The grid's callbacks do not initialize the "host" page's life cycle.
        Regards,
        Mike
        P.S. You can downgrade / upgrade the sample project I provided via the Project Converter tool. Take a look at the Upgrade Notes help topic to learn more about downgrade / upgrade procedures.

        thanks , just what I was looking for

          Hello Ian,
          Thank you for your response. Please feel free to contact us at any time.
          Thanks,
          Mike
          --------------------
          Check if Search Engine is able to answer questions faster than I do!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.