Ask a questionAsk a question
 

Answerwindow.showModalDialog problem

  • Tuesday, December 05, 2006 11:57 PMlax4u Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     


    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.

Answers

All Replies

  • Wednesday, December 06, 2006 3:53 PMlax4u Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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 06, 2006 5:51 PMa.Net Person Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hey lax4u

    Try this,

    var childWindow;

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

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

    Hope this helps.
  • Wednesday, February 14, 2007 10:11 PMdlliu Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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 28, 2007 5:08 PMkjames Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

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

    <base target="_self">

  • Monday, June 11, 2007 5:35 AMsmomair Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     kjames wrote:

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

    <base target="_self">

     

    KJames

     

    Can you elaborate this further!

  • Friday, August 17, 2007 1:22 PMgauravsatya Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    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 24, 2007 6:49 AMsahridhayan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    use this,

    "window.dialogArguments.location.href = ''

    and then window.close

     

    hope it helps

    sahridhayan

     

  • Thursday, August 30, 2007 1:47 PMTabrez Khan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

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

  • Thursday, January 24, 2008 5:29 AMlakshmideepthi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi

    thank u.u helped me so much.

  • Wednesday, February 27, 2008 12:01 AMdiffident Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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!!

  • Thursday, June 25, 2009 11:20 AMHarshil_Patel_5326c0 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    thanks a lot, it really worked by placing <base target="_self"> in the head section.


    thanks once again.

    ShadowMan : The Lord of Dead Side
  • Wednesday, July 29, 2009 5:17 PMMr Bin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Is it ok? <base ...>?

  • Wednesday, September 02, 2009 7:58 AMEJAZMOHAMMED Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Thanks every body....
    I was also worring for the same.
    anyway it helped me a lot.

  • Wednesday, September 16, 2009 9:05 AMJohn Writers Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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

    <span style="font-family:Verdana, Arial, Helvetica, sans-serif"><span style="white-space:normal"><span style="font-family:monospace"><span style="white-space:pre"><pre lang="x-c#"><%@ 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?????
  • Sunday, September 20, 2009 7:05 AMOponCodes Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks a lot
    This code help me very much
    •  
  • Friday, September 25, 2009 8:05 AMFLVwin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

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


    FLVwin is a Flash Fans!
  • Tuesday, October 27, 2009 7:24 AMGaneshKumarVKM Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I tried base under head. It works fine in IE6. But in IE 7, the same problem is there. How to rectify that?