Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Close popup from Parent window link

Posted on 2009-03-31
11
Medium Priority
?
1,024 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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 …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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