Page view counter

check whether any pop up window already opened from main page?????

Last post 01-23-2008 7:18 AM by NC01. 12 replies.

Sort Posts:

  • check whether any pop up window already opened from main page?????

    01-22-2008, 3:33 AM
    • Loading...
    • bp47580
    • Joined on 08-07-2007, 1:19 PM
    • Posts 116
    • Points 72

    i am using vs2005 and vb.net
    i am using this piece of code to pop up a window(i:e a aspx page) from a main page(also a aspx page)
    before opening that pop up window i want to check whether any pop up window from main page is already opened or not...
    if any pop up window is already opened then close this and open pop up window again
    how do i do this in vb.net....
    if i can use script then help me by providing some code...

    pop up window code..........
    gstrPopupScript = "<script language='javascript'>" & "window.open('" & ConfigurationManager.AppSettings("ActionTypeURL4") & "', 'CustomPopUp', " & "'width=800, height=600,statusbar=yes ,scrollbars=yes, menubar=no, resizable=yes')" & "</script>"
     ClientScript.IsStartupScriptRegistered(gstrPopupScript)
     Response.Write(gstrPopupScript)

    Filed under:
  • Re: check whether any pop up window already opened from main page?????

    01-22-2008, 5:26 AM
    • Loading...
    • harsha214
    • Joined on 01-08-2008, 7:45 AM
    • Posts 25
    • Points 89

     http://forums.asp.net/t/1049405.aspx

     Yes

     

  • Re: check whether any pop up window already opened from main page?????

    01-22-2008, 5:45 AM
    • Loading...
    • virendra1983
    • Joined on 11-13-2007, 8:30 AM
    • India
    • Posts 632
    • Points 3,165

    hi,

    This is how I have checked..

    var childRef = null;

    function UserAddress(page)

    { if (childRef == null || childRef.closed)

    {

    childRef = window.open(page , '','width = 550, height =500 ,top = 100, left = 260,status=1,resizable=0,scrollbars=1,addressbar=0,modal=1');

     

    }

    else

    childRef.window.focus();

    return false;

    }

    Mark as answered if it helped you..

    Virendra (MCTS)

    My SiteBlog
  • Re: check whether any pop up window already opened from main page?????

    01-22-2008, 5:52 AM
    • Loading...
    • bp47580
    • Joined on 08-07-2007, 1:19 PM
    • Posts 116
    • Points 72

    but the fact is that..
    if i use a variable in aspx.vb file...during opening a pop up...like
     gstrPopupScript = "<script language='javascript'>" & "new_window=window.open('" & ConfigurationManager.AppSettings("ActionTypeURL4") & "', 'CustomPopUp', " & "'width=800, height=600,statusbar=yes ,scrollbars=yes, menubar=no, resizable=yes')" & "</script>"
                ClientScript.IsStartupScriptRegistered(gstrPopupScript)
                Response.Write(gstrPopupScript)

    can i access that variable(i.e: new_window) in script in aspx page source to close that form..
    then how....try to answer this according to my code...

  • Re: check whether any pop up window already opened from main page?????

    01-22-2008, 6:48 AM
    • Loading...
    • virendra1983
    • Joined on 11-13-2007, 8:30 AM
    • India
    • Posts 632
    • Points 3,165

    Hi,

    Try this

    gstrPopupScript = "<script language='javascript'>" & "if(new_window==null || new_window.Closed) { new_window=window.open('" & ConfigurationManager.AppSettings("ActionTypeURL4") & "', 'CustomPopUp', " & "'width=800, height=600,statusbar=yes ,scrollbars=yes, menubar=no, resizable=yes') } else { new_window.window.focus(); return false; }" & "</script>"
                ClientScript.IsStartupScriptRegistered(gstrPopupScript)
                Response.Write(gstrPopupScript)

    And put this javascript in your code

    <script type="text/javascript">

    var new_window = null;

    </script>

    Virendra (MCTS)

    My SiteBlog
  • Re: check whether any pop up window already opened from main page?????

    01-22-2008, 8:37 AM
    • Loading...
    • bp47580
    • Joined on 08-07-2007, 1:19 PM
    • Posts 116
    • Points 72

    but its not working..

  • Re: check whether any pop up window already opened from main page?????

    01-22-2008, 8:56 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 13,275
    • Points 71,391
    • TrustedFriends-MVPs

    Add this to the aspx file

    <script type="text/JavaScript">
    var childWindow = null;

    function openWindow(windowUrl)
    {
     if ( childWindow != null && childWindow.closed == false)
     {
      childWindow.close();
      childWindow = null;
     }

         childWindow = window.open(windowUrl, 'CustomPopUp', 'width=800, height=600,statusbar=yes ,scrollbars=yes, menubar=no, resizable=yes')
    }
    </script>"

    Change your script rendering in the CodeBehind file to:

    Dim javaScript As String = "<script type=text/JavaScript>openWindow('" + ConfigurationManager.AppSettings("ActionTypeURL4") + '");</script>"
    RegisterStartupScript("OpenWindowScript", javaScript)

    Note that RegisterStartupScript has changed since version 1.1 and you will get a compiler warning with the above. See http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx for more info.

    Also note that if a PostBack occurs, you will lose your window refernce and this will not work.

    NC...

  • Re: check whether any pop up window already opened from main page?????

    01-23-2008, 12:01 AM
    • Loading...
    • bp47580
    • Joined on 08-07-2007, 1:19 PM
    • Posts 116
    • Points 72

    how to retain the value during postbacks.

    ptherwise how can i do this?

  • Re: check whether any pop up window already opened from main page?????

    01-23-2008, 12:03 AM
    • Loading...
    • virendra1983
    • Joined on 11-13-2007, 8:30 AM
    • India
    • Posts 632
    • Points 3,165

    To retain values you can use session variables.

    Virendra (MCTS)

    My SiteBlog
  • Re: check whether any pop up window already opened from main page?????

    01-23-2008, 12:15 AM
    • Loading...
    • bp47580
    • Joined on 08-07-2007, 1:19 PM
    • Posts 116
    • Points 72

    but how could i implement session in my code..
    plz give some code help..

  • Re: check whether any pop up window already opened from main page?????

    01-23-2008, 12:24 AM
    • Loading...
    • virendra1983
    • Joined on 11-13-2007, 8:30 AM
    • India
    • Posts 632
    • Points 3,165

    This is how you create a session variable

    Session["VariableName"] = assign any value to it..as for example

    Session["VariableName"] = txtbox.text;

    To access session variable again use this/

    if(Session["VariableName"] != null)

    {

    textBox2.text = Session["VariableName"];

    }

    It's always good to check for Session["VariableName"] exists or not...

    Virendra (MCTS)

    My SiteBlog
  • Re: check whether any pop up window already opened from main page?????

    01-23-2008, 4:29 AM
    • Loading...
    • kakali
    • Joined on 02-01-2007, 10:37 AM
    • Posts 133
    • Points 650

    Hi,

    window.open has a 4th optional parameter (replace: boolean) which you can use to check whether the same window is already open or not.

    var x = window.open('test.aspx', 'CustomPopUp', 'width=800, height=600,statusbar=yes ,scrollbars=yes, menubar=no, resizable=yes',true)

    x.window.focus();

    So if user click the link n number of time, only a single window will open.

    Regards
  • Re: check whether any pop up window already opened from main page?????

    01-23-2008, 7:18 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 13,275
    • Points 71,391
    • TrustedFriends-MVPs

    bp47580:

    how to retain the value during postbacks.

    ptherwise how can i do this?

    There is no way. You could only stop all PostBacks. You cannot place client-side window references into Session state. Give it up! Again -- there is no way to retain the window reference when a postback occurs!

    NC...

     

     

Page 1 of 1 (13 items)