Solved

Close popup from Parent window link

Posted on 2009-03-31
11
1,004 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

11 Experts available now in Live!

Get 1:1 Help Now