Click here to Skip to main content
15,906,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 2 pages
page 1 contains an asp button which should call a code behind function then open the page2 as a popup window
on page2 there is also an asp button which should call a function from its own code behind and another function from page1 code behind then close the popup window

in other words: I need to transfer data from page1 to page2, and prepare another data in page2 before closing and inform page1 about closing to receive the data

note: I want to do this without user permission for the popup, so registering scripts from code behind? not what I am looking for!

"I use sessions to transfer data"

What I have tried:

I tried to call an invisible asp buttons click event using javascript
It works in page1 but not always

"page1 using master page"
"page2 webform"

At this code I used
document.getElementById('ContentPlaceHolder1_HiddenButton').click();
in page1 to create the data session before opening the popup. and used
document.getElementById('HiddenButton').click();
in page2 to prepare another data session for return. also used
opener.document.getElementById('ContentPlaceHolder1_HiddenButton1').click();
in page2 to inform page1 about new data session and popup closing.

page1 code

ASP.NET
<script type="text/jscript">
     
       function OpenPopup() {
         document.getElementById('ContentPlaceHolder1_HiddenButton').click();
         window.open("WebForm1.aspx", "List", "scrollbars=yes,resizable=no,width=1000,height=600");
            return false;
        }

    </script>

 <asp:Button  ID="HiddenButton1" runat="server" Text="Button"  style="display:none"	
        OnClick="HiddenButton1_Click"/>
    <asp:Button  ID="HiddenButton" runat="server" Text="Button" style="display:none"	OnClick="HiddenButton_Click"/>

<asp:Button ID="btnOffer" runat="server" Text="Add Offer"  onclientclick="javascript:return OpenPopup();"/>


page2 code
ASP.NET
<script type="text/javascript"> 
   function returnValues() {
    
            document.getElementById('HiddenButton').click();
           opener.document.getElementById('ContentPlaceHolder1_HiddenButton1').click();
            window.close();
     
    }
    </script>

 <asp:Button  ID="HiddenButton" runat="server" Text="Button" style="display:none" OnClick="HiddenButton_Click"/>

<asp:Button ID="btnFinish" runat="server"  OnClientClick="javascript:return returnValues()" Text="finish and close" />
Posted
Updated 9-Jan-17 5:00am
v2

I just created a function on parent page(page1) as below:

function InformedFromPage2() {
           alert('from page2');
       }


And on page 2 I called the function as followed:

function returnValues() {
           opener.InformedFromPage2();
           document.getElementById('HiddenButton').click();
           opener.document.getElementById('HiddenButton1').click();
           window.close();

       }
 
Share this answer
 
Comments
M. Daban 9-Jan-17 7:06am    
great, but sometimes calling the click event for buttons doesn't work
Vincent Maverick Durano 9-Jan-17 10:58am    
it wont work if you are returning false to your onclient click event
why not learn and use AJAX to invoke server methods. That way you won't be dealing with postbacks which could cause you pain when mixing with JavaScript logic. Here's a quick reference that may help you get started: Many ways to communicate with your database using jQuery AJAX and ASP.NET[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900