locked
window.showModalDialog problem RRS feed

  • Question


  • I have button on Search.aspx page. when user clicks on that button a new window appears
    using following javascript

    function GotoSelectProgram(memberid)
    {  
     var url2 = "SelectProgram.aspx?MID="+memberid;
     str = window.showModalDialog(url2);
    }

    the above script will create new window for SelectProgram.aspx page. This new page has
    datagrid with few rows. and each row has ImageButton called Select. when user select any row
    i want to close that popup window and  parent window should navigate to ProgramUpdate.aspx

    im using following c# code in click event of select button

    private void MemberDetails1_SelectorChanged(object sender, ProgramEventArgs e)
    {  
     // some code here

     Response.Write("<script language='javascript'>window.close();window.opener.location.href = 'ProgramUpdate.aspx'</script>");     
    }

    the above code works fine if i use window.open instead of window.showModalDialog.

    but if i use window.showModalDialog, when user clicks on select, control goes to ProgramUpdate.aspx page as i wanted but
    parent window still shows Search.aspx and Popup window is still there, it wont get closed.

    Tuesday, December 5, 2006 11:57 PM

Answers

  • add this line to the child window page html...

    <base target="_self">

    Wednesday, February 28, 2007 5:08 PM

All replies

  • i'll put above question in simple way

    i have Main.aspx page with one button.
    On click event it will execute following javascript code

    function ShowDialog()

      window.showModalDialog("Child.aspx"); 
    }


    on child.aspx i have one more button
    on click event it will execute following javascript code

    function CloseDialog()
    {    
     window.close();
    }

    why its not closing Child window and control is also not going back to main window.

    Wednesday, December 6, 2006 3:53 PM
  • Hey lax4u

    Try this,

    var childWindow;

    function ShowDialog()
    {
    childWindow = window.showModalDialog("Child.aspx");
    }

    function CloseDialog()
    {
    childWindow.close();
    }

    Hope this helps.
    Wednesday, December 6, 2006 5:51 PM
  • In fact, the problem is:

    In the new window, click any button will generate a new window.

    If you don't use "close" in the script, you'll find another window shows up.

    I'm seeking the solution of this. Any advice is appreciated!

     

     

    Wednesday, February 14, 2007 10:11 PM
  • add this line to the child window page html...

    <base target="_self">

    Wednesday, February 28, 2007 5:08 PM
  •  kjames wrote:

    add this line to the child window page html...

    <base target="_self">

     

    KJames

     

    Can you elaborate this further!

    Monday, June 11, 2007 5:35 AM
  •  

    Hi

    Even i am facing the same issue.

    I even tried <base target="_self">

    Then also i am facing the issue.

     

    Any pointer will be of great help.

    Friday, August 17, 2007 1:22 PM
  • use this,

    "window.dialogArguments.location.href = ''

    and then window.close

     

    hope it helps

    sahridhayan

     

    Friday, August 24, 2007 6:49 AM
  • use <base target="_self" /> under head section

    Thursday, August 30, 2007 1:47 PM
  • Hi

    thank u.u helped me so much.

    Thursday, January 24, 2008 5:29 AM
  • Thanks Kjames. That worked. I had to add the <base target="_self" /> in the head section.

     

    I was struggling with this for the past 4 hrs!!

    Wednesday, February 27, 2008 12:01 AM
  • thanks a lot, it really worked by placing <base target="_self"> in the head section.


    thanks once again.

    ShadowMan : The Lord of Dead Side
    Thursday, June 25, 2009 11:20 AM
  • Is it ok? <base ...>?

    Wednesday, July 29, 2009 5:17 PM
  • Thanks every body....
    I was also worring for the same.
    anyway it helped me a lot.

    Wednesday, September 2, 2009 7:58 AM
  • Hi.
    I use a Master Page where I Put this code:

    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPager.Master.cs"
        Inherits="BillerManager.Web.UI.Portal.MasterPager" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Biller Manager</title>
        <asp:ContentPlaceHolder ID="head" runat="server">
        </asp:ContentPlaceHolder>
        <base target="_self" />
    </head>
    <body>
         <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
    	</asp:ScriptManager>
        <ext:ScriptManager ID="ScriptManager2" runat="server" Theme="Gray">
        </ext:ScriptManager>
        <table style="height: 100%; width: 97%; border-color: Gray;" border="2" align="center" cellpadding="0" cellspacing="0">
        <asp:Panel runat="server" ID="pnlToolbar">
    .
    .
    .
    .
    <asp:SiteMapDataSource ID="msdsMenu" runat="server" ShowStartingNode="False" />
        </form>
    </body>
    </html>

    in a ParentPage.aspx I've a GridView where I create runtime a link to open new asp with popup modal:

    protected void gvDiagnostics_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    LinkButton hyp = (LinkButton)(e.Row.Cells[0].FindControl("link"));
                   
                       hyp.Text = "Details";
                        string url = Request.Url.ToString();
    
                        string modalPopup = String.Format("window.showModalDialog('{0}?id={1}&viewTB=false','','dialogwidth: 450; dialogheight: 300; resizable: yes;');document.location.reload(true)", url, idObject.Text);                    
                        hyp.Attributes["OnClick"] = "javascript:" + modalPopup;
                            }
     }
           

    and in the child.aspx page, there is the follow code, linked a close button

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPager.Master" AutoEventWireup="true"
    	CodeBehind="LineDetails.aspx.cs" Inherits="BillerManager.Web.UI.Portal.Forms.LineDetails" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        
        <script language="javascript" type="text/javascript">
        function reloadParentAndClose()
        {
            window.close();
        }
        </script>
        
    	<table width="100%" style="background-color: white;">
    .
    .
    .
    

    This code run correctly (parent page open a child page in modal popup mode, and when I close the child page, the parent page reload it) BUT IF OPEN MY SITE WITH A IE 6.0, I RECIVE THE MESSAGE:

    "
    Internet Explorer cannot open the Internet site http://....
    Operation Aborted
    "

    I recive this message when I open my site, in default.aspx. And I recive it only when open my site with IE 6.0. If I open it with 7.0 or 8.0 I've not problem.
    If i cut the <base target="_self" />    from my Master.Page, I don't revice any error but when i close my modal popup, a new window is open with the same page......

    Any idea?????
    Wednesday, September 16, 2009 9:05 AM
  • Thanks a lot
    This code help me very much
    Sunday, September 20, 2009 7:05 AM
  • use <base target="_self" /> under head section


    FLVwin is a Flash Fans!
    Friday, September 25, 2009 8:05 AM
  • I tried base under head. It works fine in IE6. But in IE 7, the same problem is there. How to rectify that?
    Tuesday, October 27, 2009 7:24 AM
  • You cannot write a javascript function to refresh parent page from a Modal child pop-up window.

     Instead, you can put the code to refresh the page just below the line that actually opens the modal popup in the parent page. Since code exceution on parent stops at the point when the modal pop window is opened,  the next line is executed only after the modal popup has been closed. So if you put the reload call just below the call to open modal popup, the parent would refresh immediately the modal popup is closed.

    Example - To refresh parent page on closing Modal child pop-up window.
     
    ....on Parent page
     
    function OpenModalPopUP()
    {             
         window.showModalDialog('page.aspx'); 
        window.location.reload();
    }


    Cheers, Eliza
    Tuesday, March 23, 2010 11:58 AM
  • If you don't want to reopen a new page after you click or close your modal just put your content in a Ajax UpdatePanel.

    Here it's a code show how you can done this:

     

     

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" />
    <asp:Button ID="Add" runat="server" Text="" Width="50px" 
    onclick="Add_Click" />
    </ContentTemplate>
    </asp:UpdatePanel>

    And just call the below method from your parent window.

     window.showModalDialog("page.aspx"); 

     

     

    Saturday, June 19, 2010 7:48 AM
  • Thank you.  Adding window.location.reload solved the issue which is calling from master page.

    Great !  I pondered on this all night long and in the morning I saw this fix.

    Monday, December 12, 2011 5:03 PM
  • hi there,

    this is a solution to this scenario:

    1. you opened a pop-up window with the showmodaldialog method of window object in javascript

    2. if you click on any link from this modal window then a non-modal pop-up window will appear

    use <base target="_self" /> under head section

    is the solution, so that when you click on any link on this modal pop-up window, no other pop-up window is opened, and instead html in your modal window is rewritten, or you go to another page inside this modal window.

    ciao,

    tonci korsano

    Wednesday, April 18, 2012 6:47 PM