rebind gridview after popup

Last post 05-15-2008 11:59 AM by TonyDong. 9 replies.

Sort Posts:

  • rebind gridview after popup

    05-13-2008, 4:18 PM
    • Member
      52 point Member
    • bbqbbq
    • Member since 08-22-2007, 2:37 PM
    • Posts 174

    Hi,

    My situation is, I have two aspx pages, parent and child. The parent has a gridview and a button, both of them have been placed inside ajax update panel. Once user click the button from parent.aspx, it open a popup window (child) and let user insert new record for parent gridview. The child.aspx has a insert button, what I want is, once user click the insert button, it close the child.aspx and post the new record back to parent gridview, or only refresh the gridview.

    I am new to javascript, this is my code:

    parent.aspx

    <script type="text/javascript"> 

    function
    openWindow(gridviewId, datasource)

    {

    var windowUrl = 'child.aspx?gridviewId=' + gridviewId + '&datasource=' + datasource ; // datasource is the name of SqlDataSource

    var windowName = 'Popup_' + new Date().getTime();

    var windowFeatures =

    'channelmode=no,directories=no,fullscreen=no,' +

    'location=yes,dependent=yes,menubar=no,resizable=no,scrollbars=yes,' +

    'status=no,toolbar=no,titlebar=no,' +

    'left=0,top=0,width=500px,height=500px';

    window.open(windowUrl, windowName, windowFeatures);

    }

    function updateParent(gridviewId, sourceId)

    {

    var grid = document.getElementById(gridviewId);

    grid.set_dataSource(sourceId);

    grid.dataBind();

    }

     

    </script>

    child.aspx

    <script type="text/javascript">

     

    function closeWindow()

    {

    var gridviewId = '<%= Request["gridviewId"].ToString() %>';var source = '<%= Request["datasource"].ToString() %>';

    window.opener.updateParent(gridviewId, source);

    window.close();

    }

    </script>

    ....

    <asp:Button ID="btnInsert" runat="server" Text="Insert" OnClientClick="closeWindow()" />

     The problem is, I can open popup from the parent.aspx, but when I click insert from child.aspx, the popup window can not get closed and nothing happend to my parent.aspx.

     

  • Re: rebind gridview after popup

    05-13-2008, 5:49 PM
    • Contributor
      4,089 point Contributor
    • TonyDong
    • Member since 02-01-2006, 1:30 PM
    • BC, Canada
    • Posts 802

    You can do it in two ways

    on child window, use ajax or server postback to update database, and then reload parent page, and finally close the child window.

    you need javascript to do close and reload the parent page.

    window.opener.document.location.href=window.opener.document.location.href;

    (or)

    window.parent.document.location.reload();

    (or)

    window.parent.document.location.href=”ParentPage.aspx”;

    Don't forget to click "Mark as Answer" on the post(s) that helped you.
  • Re: rebind gridview after popup

    05-14-2008, 11:12 AM
    • Member
      52 point Member
    • bbqbbq
    • Member since 08-22-2007, 2:37 PM
    • Posts 174

    I tired to call window.parent.document.location.reload() inside my javascript, but still can not get parent gridview get reloaded.

    I did insert/update database from my child window, the problem is, I need find a way to let the update displayed at my parent.aspx. However, the

    gridview of my parent page is inside a ajax update panel.

    Updated:

    By searching this site, I found solution from here: http://forums.asp.net/p/1146717/2354119.aspx

     

     

     

     

     

  • Re: rebind gridview after popup

    05-14-2008, 5:35 PM
    • Contributor
      4,089 point Contributor
    • TonyDong
    • Member since 02-01-2006, 1:30 PM
    • BC, Canada
    • Posts 802

     

    Did you parent.aspx get reload it or not?

     

    Don't forget to click "Mark as Answer" on the post(s) that helped you.
  • Re: rebind gridview after popup

    05-14-2008, 11:35 PM
    • Member
      52 point Member
    • bbqbbq
    • Member since 08-22-2007, 2:37 PM
    • Posts 174

    No, my parent.aspx did not get reloaded. I therefore, followed by the method in the thread I posted before,  I added a button and called a javascript to trigger the button click event once user hit insert button inside child.aspx. This time, I got the parent.aspx reloaded. However, for some reason, even though I noticed the gridview get refreshed by the button click event, I still can not see the new record I just insert from child.aspx. I have to manully refresh the gridview to get the new record display.

    Also, I noticed that if user close child.aspx window by clicking 'x', my code has no way to refresh the parent.aspx. If you don't mind, I can post my code here again.

    TonyDong:

     

    Did you parent.aspx get reload it or not?

     

  • Re: rebind gridview after popup

    05-15-2008, 3:12 AM
    Answer
    • Participant
      1,092 point Participant
    • blodfox777
    • Member since 07-12-2007, 12:30 PM
    • Posts 159

    bbqbbq:

    No, my parent.aspx did not get reloaded. I therefore, followed by the method in the thread I posted before,  I added a button and called a javascript to trigger the button click event once user hit insert button inside child.aspx. This time, I got the parent.aspx reloaded. However, for some reason, even though I noticed the gridview get refreshed by the button click event, I still can not see the new record I just insert from child.aspx. I have to manully refresh the gridview to get the new record display.

    Also, I noticed that if user close child.aspx window by clicking 'x', my code has no way to refresh the parent.aspx. If you don't mind, I can post my code here again.

    TonyDong:

     

    Did you parent.aspx get reload it or not?

     

     

    HI bbqbbq

    the following demo works on my machine,

    It can display the new record in the GridView which in an UpdatePannel of Opener window

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Web.mdb")))
            {
                conn.Open();
                using (OleDbCommand cmd = new OleDbCommand("insert into T_About(AboutType,Contents) values('NEW','NEWNEWNEW')", conn))
                {
                    cmd.ExecuteNonQuery();
                }
            }
            Response.Write("<script language='javascript'>window.opener.document.location.href=window.opener.document.location.href;window.close();</script>");
    
        }
     

     

    Regards!

    -- "Mark As Answer" If my reply helped you --
  • Re: rebind gridview after popup

    05-15-2008, 8:29 AM
    Answer
    • Member
      66 point Member
    • mailathere
    • Member since 05-12-2008, 2:14 PM
    • Posts 8

    Hi bbqbbq. I think you should use the code like below. If you are using ajax the why you not implement all features of Ajax!!!!

    Here in this I use ModalpopupExtender, new control of ajax. and in modal popup extender you can access all controls(like textboxes).

    <div>

                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:Panel ID="pnlHeader" runat="server" Width="100%">
                    <table width="100%">
                        <tr>
                            <td>
                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                    <ContentTemplate>
                                        <table width="100%">
                                            <tr>
                                                <td>
                                                    <asp:GridView ID="gvAwards" runat="server" AutoGenerateColumns="False" EnableViewState="false"
                                                        AllowSorting="False" AllowPaging="False" DataKeyNames="mandateID" OnRowDataBound="gv_RowDataBound"
                                                        OnRowCommand="gv_RowCommand">
                                                        <Columns>
                                                            <asp:BoundField ItemStyle-CssClass="col10" NullDisplayText="N/A" DataField="activityType"
                                                                HeaderText="Activity" />
                                                            <asp:BoundField ItemStyle-CssClass="col10" NullDisplayText="N/A" DataField="entryDate"
                                                                HeaderText="Date" HtmlEncode="False" DataFormatString="{0:dd/MM/yyyy}" />
                                                            <asp:BoundField ItemStyle-CssClass="col20" NullDisplayText="N/A" DataField="assetList"
                                                                HeaderText="Asset Class" />
                                                            <asp:BoundField ItemStyle-CssClass="col20" NullDisplayText="N/A" DataField="style"
                                                                HeaderText="Style" />
                                                            <asp:BoundField ItemStyle-CssClass="col12" NullDisplayText="N/A" DataField="size"
                                                                HeaderText="Amount (GBP)" DataFormatString="{0:GBP ###,### m;N/A}" HtmlEncode="False" />
                                                            <asp:BoundField ItemStyle-CssClass="col20" NullDisplayText="N/A" DataField="managerName"
                                                                HeaderText="Manager" />
                                                            <asp:BoundField ItemStyle-CssClass="col20" NullDisplayText="N/A" DataField="consultantName"
                                                                HeaderText="Consultant" />
                                                            <asp:TemplateField HeaderText="View" ItemStyle-CssClass="col05 centre">
                                                                <ItemTemplate>
                                                                    <asp:ImageButton ID="cmdAwards" runat="server" ImageUrl="../images/arrow2.gif" CommandName="cmdAwards"
                                                                        CommandArgument='<%# Eval("mandateID") %>' />
                                                                </ItemTemplate>
                                                            </asp:TemplateField>
                                                        </Columns>
                                                    </asp:GridView>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Button ID="btnInsertNewRecord" Text="Insert new record" runat="server" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <act:ModalPopupExtender TargetControlID="btnInsertNewRecord" runat="server" ID="PopupControlExtender1"
                                                        PopupControlID="Panel1" BackgroundCssClass="modalBackground" CancelControlID="btnCancel">
                                                    </act:ModalPopupExtender>
                                                </td>
                                            </tr>
                                        </table>
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnContinue" EventName="Click" />
                                    </Triggers>
                                </asp:UpdatePanel>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:UpdatePanel ID="upComments" runat="server" UpdateMode="conditional">
                                    <ContentTemplate>
                                        <asp:Panel ID="Panel1" runat="server" Style="display: none" Width="720px" Height="370px"
                                            BorderStyle="Ridge" BorderWidth="3px" BorderColor="darkgray">
                                            <table width="100%">
                                                <tr>
                                                    <td style="width: 30%">
                                                        Activity Type
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtActivityType" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Entry Date
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtEntryDate" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Asset List
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtAssetList" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Style
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtStyle" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Size
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtSize" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Manager name
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtManagerName" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Consultant name
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtConsultantName" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="width: 30%">
                                                        Mandate ID
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtMandateID" runat="server"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        &nbsp;
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Button ID="btnContinue" Text="Continue" runat="server" />
                                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </asp:Panel>
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="btnContinue" EventName="Click" />
                                    </Triggers>
                                </asp:UpdatePanel>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </div>

     

    'Thanks 

  • Re: rebind gridview after popup

    05-15-2008, 9:50 AM
    • Participant
      1,153 point Participant
    • Dollarjunkie
    • Member since 01-28-2007, 8:18 AM
    • Posts 860

    I sort of hard similar problem myself and what I ended up doing was calling the code to Load the Gridview in the Button's Onclick Event handler, Setting the UpdatePanel control's UpdateMode to ALWAYS and then calling the click event of the Button from the Child Code right before I close it.

     

    .Net Web/Software Engineer
  • Re: rebind gridview after popup

    05-15-2008, 9:51 AM
    • Participant
      1,153 point Participant
    • Dollarjunkie
    • Member since 01-28-2007, 8:18 AM
    • Posts 860

    I sort of had similar problem myself and what I ended up doing was calling the code to Load the Gridview in the Button's Onclick Event handler, Setting the UpdatePanel control's UpdateMode to ALWAYS and then calling the click event of the Button from the Child Code right before I close it.

     

    .Net Web/Software Engineer
  • Re: rebind gridview after popup

    05-15-2008, 11:59 AM
    Answer
    • Contributor
      4,089 point Contributor
    • TonyDong
    • Member since 02-01-2006, 1:30 PM
    • BC, Canada
    • Posts 802

    You need to use onbeforeunload event to fire reload parent page

    <script type="text/javascript>

    window.onbeforeunload=reload;

    function reload(){

    //reload your parent page code here

    }

    Don't forget to click "Mark as Answer" on the post(s) that helped you.
Page 1 of 1 (10 items)