window.open and window.opener problem

 Hi,

I have written the following javascript to pop up a window

In the parent page:

function PreMail()
    {
       window.open("http://localhost:2704/WebSite3/popup1.aspx","popup1","height=50,width=300,left=500,top=400,status=no,toolbar=no,menubar=no,location=no");
    } 

and the button:

<asp:Button ID="bt1" runat="server" OnClick="Button1_Click"  OnClientClick="PreMail()" Style="left: 45px;
                        position: relative; top: -210px" Text="Send Mail" />

and in the .cs file:

protected void Button1_Click(object sender, EventArgs e)
    {
        string str = Request["Hidden1"];
        t1.Text = str;
    
    }

 

In the child page(popup1.aspx): 

function now()
    {
      window.opener.document.getElementById('Hidden1').value=document.getElementById('TextBox1').value ;
      window.close();
    }
   
    </script>
</head>
<body style="background-color: DarkOrange">
   
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server"  OnClientClick="now()" Style="position: relative; left: 15px; top: 6px;" Text="Button" OnClick="Button1_Click" />
        <asp:TextBox ID="TextBox1" runat="server" Style="left: 54px; position: relative;
            top: 0px"></asp:TextBox>

 

The problem is the textbox in the parentpage(TextBox1) gets updated with the value of the hidden field when I click the button(bt1) for the second time. What's the problem?

Thanks,

Manjunath M.R.
    

 

 

0
ManjunathMR
8/26/2008 7:16:23 AM
asp.net.client-side 24353 articles. 1 followers. Follow

4 Replies
1394 Views

Similar Articles

[PageSpeed] 14

where r u setting the value in hidden field,

need some more code, i feel that u r setting hiddenfield value in button_click() event of parent

check it it should be done before the clientclick event of bt1

 


"Mark as Answer"
-- on the post that helps you

RKChaudary
0
rkchaudary
8/26/2008 9:11:21 AM

 Hi,

This is the complete code.

popup1.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="popup1.aspx.cs" Inherits="popup" %>

<!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>
    <script  language="javascript" type="text/javascript">
    function now()
    {
      window.opener.document.getElementById('Hidden1').value=document.getElementById('TextBox1').value ;
      window.close();
    }
   
    </script>
</head>
<body style="background-color: DarkOrange">
   
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server"  OnClientClick="now()" Style="position: relative; left: 15px; top: 6px;" Text="Button" OnClick="Button1_Click" />
        <asp:TextBox ID="TextBox1" runat="server" Style="left: 54px; position: relative;
            top: 0px"></asp:TextBox>
   
   
    </form>
   
</body>
</html>

 

masterpage.master:

<%@ Master Language="C#"  Debug="true" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage"  %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!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>
<script type="text/javascript">
    function PreMail()
    {
       window.open("http://localhost:2704/WebSite3/popup1.aspx","popup1","height=50,width=300,left=500,top=400,status=no,toolbar=no,menubar=no,location=no");
    }
    </script>
</head>
<body bgcolor="#ffff66" background="http://localhost:2704/WebSite3/img1.jpg" text="#000033">
   
    <form id="form1" runat="server">
    <div id="mailDIV"  >
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
            <tr>
                <td colspan="2" style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                    &nbsp;</td>
            </tr>
            <tr>
                <td style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                    </td>
                <td style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                    <asp:Button ID="bt1" runat="server" OnClick="Button1_Click"  OnClientClick="PreMail()" Style="left: 45px;
                        position: relative; top: -210px" Text="Send Mail" />
                    <asp:ContentPlaceHolder ID="Con1" runat="server">
                    </asp:ContentPlaceHolder>
                    <input id="Hidden1" name="Hidden1" value="bb" type="hidden" />
                    <asp:TextBox ID="t1" runat="server" Style="position: relative"></asp:TextBox>
                    </td>
            </tr>
            <tr>
                <td colspan="2" style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                    &nbsp;&nbsp;
                </td>
            </tr>
        </table>
        <br />
    </div>
   
   
    </form>
</body>
</html>

buttonclick event for Button1:

    protected void Button1_Click(object sender, EventArgs e)
    {

        string str = Request["Hidden1"];
        t1.Text = str;
    
    }
    

I guess first the clientclickevent executes and then the click event. Or is it the other way.

 

Thanks,

Manjunath M. R. 

 

 

 

0
ManjunathMR
8/26/2008 10:12:34 AM

Hi,

onclientclick of button in masterpage popup opens and then executes server click event (on masterpage)

at this time Hidden1 has no value (so t1 will be empty)

in popup window you are setting some value in hidden field (of master page) on click of a button in popup window

when second time you click button in master page first popup opens then executes server click event (on master page)

at this time Hidden1 has a value so it will put that value in t1. this is the reason it is working in second click event.

put this

window.opener.location.href = window.opener.location.href;

in popup1.aspx  in new() method line before window.close();


"Mark as Answer"
-- on the post that helps you

RKChaudary
0
rkchaudary
8/26/2008 11:09:45 AM
HI ManjunathMR
 

Ravi’ analysis is right. However, if you would like to follow Ravi’ suggestion, you need make the Hidden Field run at server-side, because the <input type=’hidden’> is a client-side element, its value will be clear after page reload:


window.opener.location.href = window.opener.location.href;
 

So, I suggest you change your code like following, I think it will meet your needs:


  
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
<script type="text/javascript"> 
    function PreMail() 
    {
        window.open("popup1.aspx","popup1","height=50,width=300,left=500,top=400,status=no,toolbar=no,menubar=no,location=no");
    } 
    
    function SendMail()
    {
        document.getElementById('<%= bt1.ClientID %>').click();
    }
    </script>
</head>
<body bgcolor="#ffff66" background="http://localhost:2704/WebSite3/img1.jpg" text="#000033">
    
    <form id="form1" runat="server">
    <div id="mailDIV"  >
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
            <tr>
                <td colspan="2" style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                     </td>
            </tr>
            <tr>
                <td style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                    </td>
                <td style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                    <asp:Button ID="bt1" runat="server"  style="display:none"  OnClick="Button1_Click"  Text="Send Mail" />
                    <input id="Button1" type="button" value="Send Mail" onclick="PreMail();"/>
                    <asp:ContentPlaceHolder ID="Con1" runat="server">
                    </asp:ContentPlaceHolder>
                    <input id="Hidden1" name="Hidden1" value="bb" type="hidden" />
                    <asp:TextBox ID="t1" runat="server" Style="position: relative"></asp:TextBox>
                    </td>
            </tr>
            <tr>
                <td colspan="2" style="font-size: xx-large; color: black; font-style: normal; height: 100px;
                    background-color: transparent">
                      
                </td>
            </tr>
        </table>
        <br />
    </div>
    
    
    </form>
</body>
</html>




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="popup1.aspx.cs" Inherits="popup1" %>

<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <script  language="javascript" type="text/javascript">
    function now()
    {
      window.opener.document.getElementById('Hidden1').value=document.getElementById('TextBox1').value ;
      window.opener.SendMail();
      window.close();
    }
    
    </script>
</head>
<body style="background-color: DarkOrange">
    
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server"  OnClientClick="now()" Style="position: relative; left: 15px; top: 6px;" Text="Button" OnClick="Button1_Click" />
        <asp:TextBox ID="TextBox1" runat="server" Style="left: 54px; position: relative;
            top: 0px"></asp:TextBox>
    
    
    </form>
    
</body>
</html>
 

 
 
I look forward to receiving your test results.
 
Thanks.
 

 


Lance Zhang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Lance
8/29/2008 3:58:28 AM
Reply:

Similar Artilces:

window.open and window.opener
Sorry for a really dumb post. I am not a scripting person... I find the whole thing a bit strange really with losely coupled types ect...Anyway, I am putting together a ASP.NET v2 application. One of the pages I am planning on implementing a link to open a pop-up window. In this popup window, the user will select the location of somthing, the window close and the value returned back to one of the parent browsers controls. I know this is not rocket science and I have done endless searches to try and find the answer. I am loading up the page and passing in the ClientID of the control I wish to...

Open a new window with window.open()
Hi, =20 in our web application, we try to open a popup-window with window.open(). But instead of opening a new window, a new tab is opened. =20 In the SeaMonkey preferences, we configured it, to open new links in a new tab. With firefox, we had the same preferences, but when window.open() was called, a new window was opened.=20 How can we configure SeaMonkey, so that it has the Firefox behavior when calling window.open() ? =20 Thanks in advance. =20 =20 =20 Artur Zeiler schrieb: > Hi, > > in our web application, we try to open a popup-window wi...

window.open to open very small window
Hi, in Loggedoutmsg.aspx i am just writing- "YOU HAVE LOGGED OUT"newwin=window.open('Loggedoutmsg.aspx','Congrats',"location=0,status=0,scrollbars=0,width=300,height=1");  I want to open window just to show this line. But the window which gets opened by above code has hight more than necessary. Even when i specified height=1,its size not decreasing to show just one line .How can i do this? Please Mark the post as "ANSWER" if it helps you Answered here: http://forums.asp.net/t/1308177.aspx NC...   Heres something fro...

opening new window other than window.open
is there any other way of opening a new window... aside from window.open? window.open has a memory leak so i want to prevent using it as much as possible.Alvin ShihSoftware DeveloperMCP MCTS MCPD Hi window.showmodaldialog() but supports only IE....   Regards Suresh Kumar Goudampally Why dont you avoid pop up windows all together and use an iframe that is positioned over the content? Eric Pascarello.com | Twitter epascarello | LinkedIn Hi,Try Target="_blank" N.P.SenthilSoftware Engineer  Link buttons targer property is set to "_blank"...

maximize a window opened by window.open()
hi I want to allow the user to maximize the window opend by window.open() method sued in a ajax update panel ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, this.UpdatePanel1.GetType(), "NewClientScript", "window.open('help.aspx?','Report', 'width=500,height=400 ,top=210,left=505, scrollbars=yes');", true); Just have a look for this link it will give you all details in window.open() http://www.javascript-coder.com/window-popup/javascript-window-open.phtml   ...

how can I use window.opener but with window.showModalDialog instead of window.open
Hi, I tried the code bellow that I found in  :  4guysfromrolla site:the code displays a source page, whn I click on the Calendar <a href />  link  i get a calendar displayed on a target page. when I select a date, the calendar page closes and populates the textbox txtDate with the chosen date. Here is the code of the 2 pages and my question is down bellow:a source page called frmCalendar.aspx has this:<form name="frmCalendar">   <input name="txtDate" type="text" />   <a href=&q...

window.open() opens new window
Firefox 19.0 Windows XP Pro SP-3 Example site URL: http://www.pcconnection.com/ (I've hit this problem at many sites, however.) Firefox is configured (enabled) as: Tools -> Options -> Tabs "Open new windows in a new tab instead" = Enabled Presumably this means when a page tries to open a new window (another instance of the web browser) that instead a new tab will appear in the current window. Works that way in IE8 (when "Always open popups in a new tab" is enabled). Go down the page and click on the "Site Help" link. What I get...

Problem with opening new window "window.Open" using javascript
I am trying to open new window when press a button "btnPrint" using: Response.Write("<script language='javascript'> window.open('CouponReport.aspx', 'window', 'HEIGHT=600,WIDTH=820,top=50,left=50,toolbar=yes,scrollbars=yes,resizable=yes'); </script>"); but when the new window opened the current page do a post back action and the current page format change like the following: before window open: after window opened: So, how i can a void the post back action.  <script language='javascript'> funct...

superreview granted: [Bug 429926] Make Cmd+T open a new window when no browser windows are open : [Attachment 316692] BrowserOpenTab() even when no windows are open
neil@parkwaycc.co.uk <neil@httl.net> has granted Stefan <stefanh@inbox.com>'s request for superreview: Bug 429926: Make Cmd+T open a new window when no browser windows are open https://bugzilla.mozilla.org/show_bug.cgi?id=429926 Attachment 316692: BrowserOpenTab() even when no windows are open https://bugzilla.mozilla.org/attachment.cgi?id=316692&action=edit ...

superreview requested: [Bug 429926] Make Cmd+T open a new window when no browser windows are open : [Attachment 316692] BrowserOpenTab() even when no windows are open
Stefan <stefanh@bluebottle.com> has asked neil@parkwaycc.co.uk <neil@httl.net> for superreview: Bug 429926: Make Cmd+T open a new window when no browser windows are open https://bugzilla.mozilla.org/show_bug.cgi?id=429926 Attachment 316692: BrowserOpenTab() even when no windows are open https://bugzilla.mozilla.org/attachment.cgi?id=316692&action=edit ...

Changing the opening window url from the opened window
Hi. I would like to create the following process: The current window the user is in will open another window using the javascript window.open method. In the opened window, when I click a certain link, which is set dynamically using vb.net code, the original window (the opener) will be redirected to the url that was set in the link. How can I do this ? Thanks in advance. check related postshttp://www.experts-exchange.com/Web/WebDevSoftware/UltraDev/Q_20754699.html  http://lists.evolt.org/pipermail/javascript/2003-March/004689.html If this post was useful to you, pl...

OPEN NEW WINDOW USING window.open
Hi, can any eagle eyed geniuses spot what I'm doing wrong here? It's doing my nut! I'm simply trying to call a new page in a new window that I want to control the size, etc. I've tried two different ways - one from within my code behind and the other triggered by a LinkButton command action. Both do absolutely nothing. Please help... Private Sub InfoClick1(ByVal pSiteCode) Response.Write("<script>window.open('siteinfo.aspx?sitecode='" & pSiteCode & "','Info','left=20,top=20,height=500,width=850,toolbar=no,status=no,resizable=1,scrollbars=no')</script>") End Sub +...

Open Popup Window and Close the window that Opened it
I'm using some code that I found on this site to open a Popup window with a Button Click for a Crystal Report: Dim PopUpScript As String = "<script language='javascript'>" + "window.open(" & Chr(39) & strExportFile & Chr(39) & ");</script>" Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopUpWindow", PopUpScript, False) After the Popup Window shows the Report I would like to close the window that opened this popup window.  Thanks, Mark just add window.close(); in Dim PopUpScript As String ...

window.open client/server side problem
I have a page with a date picker, a list box and 2 buttons. When the user chooses a date and clicks the first button, it will bring back a list of files from an FTP site and add the filenames for that date to a list box. The second button will open the file the user selects in the listbox. We had huge issues getting access to the files when the project was published. The following code to open the files has NOT worked on a non-local server:        Dim o As Object = Nothing        Dim ie As New SHDocVw.InternetExplorerClass&...

Web resources about - window.open and window.opener problem - asp.net.client-side

Problem novel - Wikipedia, the free encyclopedia
Working class, or proletarian novels are often also social problem novels . This was in many ways a reaction to rapid industrialization , and ...

Martin Place, we have a problem
A change in global conditions means that the positive economic momentum provided by a weakened Aussie dollar could soon come to a screeching ...

STEM Crisis: NSW Education Minister Adrian Piccoli to focus on STEM's image problem
They are seen as domains for &quot;geniuses&quot;, &quot;geeks&quot;, &quot;nerds&quot; and &quot;not for girls&quot;. And it's holding the nation ...

Apple’s App Store has a copyright infringement problem, business owner claims
... iOS apps scraping content from the web and packaging it in paid apps. While developer relations issues often get a lot of attention, the problem ...

Marco Rubio accidentally stumbles on the problem with religious pandering
... plan for the universe and for our lives that we are just not going to know the answer to. God’s ways are not our ways.” There are two problems ...

Recharge Wrap-up: Formula E battery award, Tesla NOx problem
Filed under: Government/Legal , Green , Motorsports , Plants/Manufacturing , Tesla , Emissions , Fuel Efficiency , Technology , Electric Williams ...

Apple's App Store has a copyright problem
... then made more apps — all of which are paid-for — and Raub says Apple is unwilling to help this time. 9to5Mac points out that this problem ...

Just Cause 3 PC graphics problems reported
Fans complain of visual bugs and glitches as developer cites issues with latest AMD graphics drivers.

Obama Claims Fish Swim In Miami Streets Because Of Climate Change — There’s Only One Problem
Obama Claims Fish Swim In Miami Streets Because Of Climate Change — There’s Only One Problem

A patch for Just Cause 3's performance problems is in the works
... of the best open-world tools ever”. It seems like it's a good game, but there have also been a lot of complaints about huge technical problems ...

Resources last updated: 12/4/2015 8:50:02 AM