Wednesday, 6 May 2015

Partial Refresh Parent window when popup child window close

In C# dot net web application, if you add a Master entry through a popup window, then that data should display in the Transaction dropdown in Parent Window without full refresh of Parent window.
It is a tricky to call a hidden button event in Parent Window from Popup Window.

Step 1: (Parent.aspx) Design Parent Window.

<asp:Button ID="btnShowPopup" runat="Server" CssClass="btn"
Text="If not found, Click here to Add Container." OnClick="btnShowPopup_Click" />

<asp:Button ID="btnHidden" runat="Server" Style="display: none" OnClick="btnHidden_Click" />

 Step 2: (Parent.cs) 
protected void btnShowPopup_Click(object sender, EventArgs e)

    string url = "Child.aspx?Id=" + ddlLiner.SelectedItem.Value;
    string popupScript = "<script language='javascript'>'" + url + "',       'Container', " + "'left = 300, top=300, width=400, height=201, " +                                 "status=no, toolbar=no, location=no, menubar=no,addressbar=0,resizable=no')" +
Page.ClientScript.RegisterStartupScript(GetType(), "PopupScript", popupScript);

protected void btnHidden_Click(object sender, EventArgs e)
GetContainer();  //Method for populate Container number in the drop down list

Step 3: (Child.aspx) Design Child Window

Here you can add Container No. one by one and save in database.  Now click on the Exit button will refresh the parent window partially.
<script language="Javascript" type="text/javascript">
        function RefreshParent() {

<asp:ImageButton ID="btnExit" runat="server" ImageUrl="images/Exit.png" Width="30px"
Height="30px" OnClientClick="RefreshParent();" ToolTip="Exit" />

//Thats all. Enjoy :)