Solved

Close popup from Parent window link

Posted on 2009-03-31
11
1,019 Views
Last Modified: 2012-05-06
I have a parent window with two LinkButtons, one is to open the popup and one is to close the popup, it is opening the popup but it not closing and when the Close popup link is clicked in the parent window then  the popup should gets close and parent should redirect.
please help its urgent
Design Aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testt.aspx.cs" Inherits="TrainingCenter_testt" %>
 
<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;
                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Open Popup</asp:LinkButton><br />
                <br />
                <br />
                <br />
                <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Close popup</asp:LinkButton>
        <br />
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>
 
 
 
 
 
Code file
 
public partial class TrainingCenter_testt : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "pop", "var child1=window.open('popup.aspx',null,'height=300,width=575,location=no,status=no,toolbar=no,dialog=yes,resizable=no')", true);
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "pop", "parent.child1.close()", true);
        Response.Redirect("~/Login.aspx");
    }
}

Open in new window

0
Comment
Question by:mannevenu
  • 5
  • 5
11 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 24037083
"parent.child1.close()" -> "this.child1.close();"

0
 

Author Comment

by:mannevenu
ID: 24037186
No its not working
only the parent page is getting redirected but popup is still opened but my requirement is parent page should be redirected and child popup should be closed
0
 
LVL 28

Expert Comment

by:sybe
ID: 24037218
Any javascript errors? What does the HTML-source of the page look like?

Using PostBack will load the same page again, but reloading the page will disconnect the popup from the page. You might want to write the "linkbutton" in plain HTML and/or not have it runat="server".

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:mannevenu
ID: 24037442
I have already given the source just copt and paste it in ur new aspx page
and code in aspx.cs file
0
 
LVL 28

Expert Comment

by:sybe
ID: 24037478
> I have already given the source just copt and paste it in ur new aspx page

You did not give the HTML-source. Open the page in your browser and do a "view source".
0
 

Author Comment

by:mannevenu
ID: 24037823
<!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><title>
      Untitled Page
</title>
   <script type="text/javascript" language="javascript">
   function closepopup()
   {
   parent.child1.close();
   }</script>
</head>
<body>
    <form name="form1" method="post" action="testt.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTUyNDA3OTkxM2Rky01k4WMmCbB0X1c2zsj4CsLiVXM=" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
// -->
</script>


    <div>
       
                <a id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')">Open Popup</a><br />
                <br />
        <span id="Label1"></span><br />
                <br />
                <a id="LinkButton2" href="javascript:__doPostBack('LinkButton2','')">Close popup</a>
           
        <br />
        <br />
        <br />
   
    </div>
    </form>
</body>
</html>
0
 
LVL 12

Expert Comment

by:Sinoj Sebastian
ID: 24037923
try this function


 
protected void LinkButton2_Click(object sender, EventArgs e)
    {
        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "pop", "this.child1.close();window.location='Login.aspx'", true);
    }

Open in new window

0
 
LVL 28

Expert Comment

by:sybe
ID: 24037959
<a id="LinkButton2" href="javascript:__doPostBack('LinkButton2','')">Close popup</a>

This is not closing the popup, but posting the page to itself. What you need is this:

<a id="LinkButton2" href="javascript:closepopup();">Close popup</a>
0
 

Author Comment

by:mannevenu
ID: 24048286
yeah letme try this one
0
 
LVL 28

Accepted Solution

by:
sybe earned 500 total points
ID: 24048397
alternatively you could have an unonload listener in the body

<body onunload="if(this.child1){this.child1.close();}">
0
 

Author Closing Comment

by:mannevenu
ID: 31565190
thank u sir its working
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question