Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to send a single variable to Popup window

    Hello folks,

    I have a very simple problem...but stuggling with this.

    I have a popup window (.aspx page). It will called from a parent .aspx page. All I want to do is read the name of the parent aspx page in popup page. Based on the name of the parent window, in the page_load event of the popup window, I want to execute some code.

    But the only catch is that, I am not able to read the parent window name until the page_load event (of popup window) complets the execution.

    1. calling popup window from parent window.

    Code:
    Code:
    function OpenWindow_HistoricalRuns() {           
                
                var windowIncsimHistRuns = window.open('MVal.aspx', 'Market', 'width=350,height=425,scrollbars=0');
    
                windowIncsimHistRuns.moveTo(500, 300);
    
            }
    In the body of the popup window the following function tries to read the parent window name:
    Code:
    function SetDisplay() {
    
                  document.getElementById('<%=TextBoxSourcePageName.ClientID%>').value = window.parent.name;
                 
              }
    In the page_load event of the popup window, I want to see what is value of TextBoxSourcePageName control. I hoped I will get 'MarketVal'. But I never get anything.

    Code:
    protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!this.IsPostBack)
                {
                    try
                    {
                        if (TextBoxSourcePageName.Text == "MarketVal")
                   }
               }
            }
    In my situation, I need to know the window.parent.name by the time Page_load event gets triggered on the popup window. Because I have to do some specific thing in the Page_Load event (of popup window), based on window.parent.name.

    So my fundamental question is, which one will get fired first in an .aspx page.

    1. Javascript in the body tag
    or 2. Page_load event of the .aspx page.

    If Javascript function in the body tag gets fired first, then by the time I get to Page_Load event, I should already have whatever I need.

    thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    > In my situation, I need to know the window.parent.name by the time Page_load event gets triggered on the popup window.

    You can't, using JavaScript.

    You apparently don't understand the loading cycle of an ASP.NET Page. Or any page served up by a web server.

    JavaScript DOES NOT AND CAN NOT execute *UNTIL* the page is sent from the server to the browser.

    And with ASP.NET, Page_Load occurs *BEFORE* even the <html> tag is sent to the browser! (It has to be! Because in Page_Load you could opt to do a Response.Redirect, and you can't redirect once *ANYTHING* has been sent to the browser...even the headers that are sent before the <html> tag.)

    There is no possible way for you to have JavaScript send some value back to the ASP.NET server before the ASP.NET Page_load event occurs. (I don't think there is any way to do this before the entire end of the ASP.NET page creation cycle. I can't think of one, anyway.)

    There is, however, a trivial way to do this:
    Code:
    var windowIncsimHistRuns = window.open('MVal.aspx?opener=' + window.name, 'Market', ... );
    And then simply have your ASP.NET code look for Request.QueryString("opener")
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    bnath001 (03-05-2012)

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Mr.Old Pedant.

    I was focusing on Javascript and forgot to think about asp.net page cycle. Let me go thru asp.net page cycle chapters in the books I have.

    REgards & thanks again
    nath

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Old Pedant,

    This is what I did.

    Code:
    function OpenWindow_HistoricalRuns() {
    
    
    
    
                var windowIncsimHistRuns = window.open('MVal.aspx?opener=' +window.name, 'MarketVal', 'menubar=1,width=350,height=425,scrollbars=0');
                
    
                windowIncsimHistRuns.moveTo(500, 300);
    
            }
    In the Page_Load event of the popup window, I did

    Code:
    string v = Request.QueryString["opener"];
    I am getting always "" (empty string) in the variable v.

    Anything wrong I am doing in the syntax?
    thanks

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Are you sure that the window you are coming from *HAS* a name?

    Windows don't have names unless you explicitly set them.

    Find out by doing this:
    Code:
    function OpenWindow_HistoricalRuns() {
        alert("The name of this window::" + window.name + "::");
        window.open('MVal.aspx?opener=' +window.name, 
                    'MarketVal', 
                    'menubar=1,top=300,left=500,width=350,height=425,scrollbars=0');
    }
    Notice how I avoided the need for the call to moveTo.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I actually gave a name to the window that calls the popup window.

    by saying window.name = "MVal'; I am also able to read that name of the window in Page_Load event of the window that is opened.

    But now, the issue is the popup is no longer a popup window. It is a full page loaded like a content form. It loads as a new page (not a small popup anymore). So what I learnt is if you want a .aspx page to load as a popup you can't pass paramters using '?' from the main page. Is that true.

    Thanks

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Shouldn't be. ASP.NET doesn't control the opening or sizing of the windows. That is 100% a browser-side capability and decision.

    I think you need to look elsewhere for the problem.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for your help so far.

    I will try to get help somewhere else.

    Regards

  • #9
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,335
    Thanks
    11
    Thanked 588 Times in 569 Posts
    you can do anything, don't give up.

    simply put a sentinel on your dependancy-having function:



    Code:
    function SetDisplay() {
           if(!window.parent || !window.parent.name){return setTimeout(SetDisplay ,100);}
                  document.getElementById('<%=TextBoxSourcePageName.ClientID%>').value = window.parent.name;
                 
              }

    (changes in red)
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    When I said to look elsewhere, I meant that the error is probably in the JavaScript code. You didn't show us the latest version of that code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •