determine whether current page is opend from window.open function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vinod allapu
    New Member
    • Apr 2009
    • 28

    determine whether current page is opend from window.open function

    hi all,

    I have a aspx page which can be opened directly or it can be opened from other aspx page using javascript window.open .... now i need to check whether it is open from a parent page or directly

    can any one please help me

    thanks
  • maliksleo
    New Member
    • Feb 2009
    • 115

    #2
    Originally posted by vinod allapu
    hi all,

    I have a aspx page which can be opened directly or it can be opened from other aspx page using javascript window.open .... now i need to check whether it is open from a parent page or directly

    can any one please help me

    thanks
    you may pass some variable from your javascript and match it on that page to check weather its open directly or from your javascript.

    maliksleo

    Comment

    • balame2004
      New Member
      • Mar 2008
      • 142

      #3
      You can use a session object to check it out.

      Comment

      • vinod allapu
        New Member
        • Apr 2009
        • 28

        #4
        hi boss thanks for reply,

        actually i have a page for entering book details and in that page i have addnewauthor button (option for user to add a new author if Author not exists in the dropdown list). soon user press addnewAuthor button it pop ups the authorpage to enter author details. soon he insert the author details the author name will be displayed in dropdown list of books page.


        And now while user wants to insert authors details individually in the authorpage Then the process of displaying the inserted author in book page is not needed. so i have to check if the current author page is pop up page or individual page. Is the process of checking the page is popup or not can be done in cs file using this.page.paren t?

        can any one solve my problem

        thanks

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by vinod allapu
          Is the process of checking the page is popup or not can be done in cs file using this.page.paren t?
          No.

          Your C# code knows nothing about browser windows. Browser windows are opened and dealt with client side, not server side. Your C# code runs on the server and has no idea about the relationship between browser windows....how could it?

          You opened your child window using JavaScirpt right?

          You have something like:
          Code:
          <script type="text/javascript">
          function OpenAuthorWindow(){
            window.open("Authors.aspx","ManageAuthors", "toolbar=no, menubar=no, width=980, height=550, resizable=yes, scrollbars=yes"); 
          
            return false;
          }
          </script>
          And you call this from your button like:
          Code:
          <asp:Button id="manageAuthors" onclientclick="return OpenAuthorWindow();" Text="Add Author"/>
          Or something like:
          Code:
          manageAuthors.Attributes.Add("onclick","return OpenAuthorWindow();");
          Anyways, you have code that opens the child window.....

          You're going to need at least 2 more JavaScript functions to make this work: one in the parent window that updates the DropDownList, and one in the child window that calls the JavaScript function in the parent window when the user is finished adding a new Author.

          Let's start with the JavaScript that updates the DropDownList.

          I would place the DropDownList in an UpdatePanel so that when it is updated it doesn't cause the whole page to update.

          Now here's a little trick to get it to update.
          Place a LinkButton or a Button in the same UpdatePanel as the DropDownList, give it an ID and set it's css style to Display:None so that it's invisible to the user:

          Code:
          <asp:UpdatePanel id="DropDownListUpdateSection" runat="server" UpdateMode="Conditional" >
            <ContentTemplate>
                <asp:DropDownList id="authorsList" runat="server"></asp:DropDownLIst>
                <asp:Button id="updateAuthorsList" runat="server" text="update authors" style="display:none;" />
            </ContentTemplate>
          </asp:UpdatePanel>
          Now write a JavaScript method that calls the JavaScript __doPostback method for the button:

          Code:
          <asp:UpdatePanel id="DropDownListUpdateSection" runat="server" UpdateMode="Conditional" >
            <ContentTemplate>
                <asp:DropDownList id="authorsList" runat="server"></asp:DropDownLIst>
                <asp:Button id="updateAuthorsList" runat="server" text="update authors" style="display:none;" />
          
            <script type="text/javascript">
              function UpdateAuthorsList() {
                __doPostBack('<%=updateAuthorsList.ClientID %>', '');
              }
          </script>
            </ContentTemplate>
          </asp:UpdatePanel>
          Ok, so now we have a JavaScript function that causes a hidden button to postback to the server.

          You need to implement a method that handles the hidden button click event so that it re-populates the Authors DropDownList when it is clicked.

          After you're done with that, you need to move to the Authors Editing page (the page that will be opened in the child window).

          You need to implement a JavaScript method that calls the JavaScript method we just implemented.

          After trying this out myself in many browsers, here's the code that will work:

          Code:
              <script type="text/javascript">
                  //You must use the setTimeout method in both of the following functions
                  //in order for the main page to be updated in FireFox version 2.
          
                  //window.onbeforeunload = updateParent;
                  function updateParent() {
                      try {
                          if (window.opener && !window.opener.closed) {
                              var win = window.opener;
                              window.opener.setTimeout(win.UpdateAuthorsList, 100);
                          }
                      } catch (err) { }
                  }
                 // function CloseBrowserWindow() {
                 //     window.close();
                 // }
              </script>
          This code checks whether or not a parent page exists before attempting to call the JavaScript that updates the DropDownList. If the parent page doesn't exist, it doesn't do anything. You just have to call this method whenever you need it.

          You'll notice some code that has been commented in the above posted JavaScript snippet. If you uncomment this code the method will be called whenever the page is unloaded (whenever a full page postback happens, or if the user leaves the website, or if the window is closed). This does not work in the Opera web browser though because it doesn't support the onbeforeunload JavaScript event. You can call this method during any event though...like a button click event for instance.

          Hope this helps.

          -Frinny

          Comment

          Working...