Solved

Close popup from Parent window link

Posted on 2009-03-31
11
1,009 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
A short film showing how OnPage and Connectwise integration works.

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now