What are the methods for establishing communication between two aspx pages with the help of JavaScript?

I have two aspx pages, one.aspx and two.aspx, and a JavaScript file named link.js.

My goal is to establish communication between these two aspx pages using the JavaScript file as an intermediary.

In the one.aspx file, I have a ModalPopupExtender with its panel content located in two.aspx. This means that in "one.aspx" :

<html>
<head>    
<script type="text/javascript" src="link.js"></script>

<script type="type="text/javascript">
   function test(){
     var str=callPopup();
     document.getElementById('pnlPopUp').innerHtml = str;
   }
</script>
</head>
<body>
<ajaxToolkit:ModalPopupExtender ID="popup1" runat="server" TargetControlID="btnOK" CancelControlID="btnCancel" PopupControlID="pnlPopUp"></ajaxToolkit:ModalPopupExtender>

<asp:Panel ID="pnlPopUp" runat="server"></asp:Panel>

  </body> 
</html>

In "two.aspx" :

<html>
  <head>
    <script type="text/javascript" src="link.js"></script>
   </head>
  <body>
<asp:Panel ID="pPanel1" runat="server">
    <table>
        <tr>
            <td>
                <p>test</p>
            </td>
            <td>
                <asp:Button ID="BtnTest" runat="server" Text="Click" OnClientClick="javascript:alert('hello world..!'); return false;" />
            </td>
        </tr>
    </table>
</asp:Panel> </body> </html>

In link.js:

function callPopup() {
    var s = document.getElementById('pPanel1').innerHtml;
    return s;
}

I am able to call callPopup() from one.aspx but unable to retrieve the content from two.aspx page. Please assist me with this issue.

Thank you in advance.

Answer №1

Here are two different methods you can use to achieve this:

  1. Utilize SignalR to send messages to multiple clients simultaneously. Learn more about SignalR here.

  2. (This method is more low-level as SignalR typically handles most of the work for you)

Another approach is to employ Ajax to invoke a server-side function. You can find more information on Ajax at this link. The server-side function can then write data to an output source such as a file, session, or cookie.

The other webpage can continuously read from the same output source (file, session, or cookie) through Ajax.

Answer №2

Have you considered whether your architecture is truly correct? Do you really have a valid reason for needing two.aspx - wouldn't one.aspx suffice?

Based on my past experience with the AjaxToolkit, I find it hard to justify its use in modern web development. Have you explored alternatives like or Backbone? They may be more suitable options.

I understand that this doesn't directly address your question, but I just want to prevent you from encountering unnecessary challenges.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide to using select2.js to activate a selection based on a data attribute

I'm faced with the following html snippet: <div class='multiWrapper'> <select id="multi" class="js-dropdown-from-code"> <optgroup class='def-cursor' label='Code' data-city ...

Is there a way to restrict input to numeric characters exclusively in Swal Sweetalert?

I'm wondering how I can restrict input to only numeric values in this section. { title: "Dollar Amount?", text: "How much is your Dollar Question worth?", inputPlaceholder: "Enter Amount" } I'm currently utilizing a Sweetalert p ...

Terminate the HTTPWebRequest upon server failure

I recently developed a Windows Service that interacts with an API through HTTPWebRequest to retrieve JSON data. However, the API only responds when it has new information to provide. To accommodate this, I have set a high timeout value to keep the request ...

Guide to extracting a key from a specific index within JSON using Google Apps Script

Is there a way to extract values key11-key44? Just managed to retrieve values key1-key4: const data = JSON.parse(UrlFetchApp.fetch(url, options); const keys = Object.keys(data.paths); for (let a in keys) {return keys[a]} { "id": &q ...

Ensuring the accuracy of input data in all input fields with the help of dojo

1)In my Dojo widget, I have two additional widgets loaded inside. If I need to clear all text boxes within the widget, I currently use this method: this.myAttachPoint.value="". Is there an alternative code that can achieve the same result without adding ...

Identify numbers and words within a sentence and store them in an array

Looking to split a string into an array based on type, extracting numbers and floats. The current code is able to extract some values but not complete. var arr = "this is a string 5.86 x10‘9/l 1.90 7.00" .match(/\d+\.\d+|\d+&bsol ...

Troubleshooting MS Word Automation in C#: Issue with type casting from 'System.String[*]' to 'System.String[]'

In my endeavor to retrieve a String array containing headings from a MS Word 2007 document (.docx), I have employed the following code: dynamic arr = Document.GetCrossReferenceItems(WdReferenceType.wdRefTypeHeading); After inspecting the arr variable thr ...

Stop the reloading of the parent page when the exit button is pressed on the popup screen

I have set up a modal popup that appears when a user clicks on a specific link. Inside the popup, I have included an exit button to close it. However, I am facing an issue where clicking on the exit button not only closes the popup but also reloads the par ...

What is the best way to determine the number of queryClient instances that have been created?

Currently, I am managing a large project where the code utilizes useQueryClient in some sections to access the queryClient and in other sections, it uses new QueryClient(). This approach is necessary due to limitations such as being unable to invoke a Reac ...

jshint Issue: Module 'underscore' Not Found

My grunt task is running smoothly, yet I keep encountering the following error every time: Loading "jshint.js" tasks...ERROR >> Error: Cannot find module 'underscore' Is there a way to determine the cause of this issue? The /grunt-contrib ...

Showing child elements within a div using AngularJS

I am eager to create a straightforward AngularJS website that will showcase an initially hidden HTML element along with all of its children. Below is the HTML structure snippet I plan to use: <div class="hiddenStuff"> <h3>Game Over</h3&g ...

Establishing a secondary Node.js service for local communication with Parse Server

My current project involves using Node.js + Parse Server for an application. I have been utilizing the Parse SDK from the client side, but there are still many changes and refactors that need to be made. One issue I am facing is that certain logic should b ...

A snippet of jQuery programming that enables automatic transitions between images

Trying to figure out how to achieve this - I want an image to change every 3 seconds using jquery. Can anyone help me with this? Unfortunately, I haven't been able to find any resources on this specific topic. ...

Access the value of a JavaScript global variable using Selenium in Python

I need to access a value from a global variable in JavaScript: clearInterval(countdownTimerTHx); var saniye_thx = 298 // <--- Variable here function secondPassedTHx() { https://i.sstatic.net/odIbh.png My goal is to retrieve the value " ...

Tips on defining the specific CSS and JavaScript code to include in your Flask application

I am currently working on a web application using Flask and I need to specify which CSS and JS files should be included in the rendered HTML page based on a condition. There are times when I want to include mycss1.css and myjs1.js: <link href="/sta ...

Make changes to the DOM element before it finishes loading

Is it possible to manipulate an object in a DOM before it's fully loaded? I am attempting to adjust the following object: (function (g) { var d = document, i, am = d.createElement('script'), h = d.head || d.ge ...

Is there a way to invert the orientation of an object within a canvas?

As I was experimenting with Javascript, I attempted to implement a feature where my 'Player' character would fall down after reaching a jumpDistance of 50. The idea was to simulate a small jump-like motion for the player. While the code may not ...

Acquire by Identifier - Tonic()

Currently, I am in the process of setting up a code example on tonicdev.com for my open-source React component available on Npm. Below is the code snippet that I am attempting to execute (editable live on tonicdev.com here): var React = require('rea ...

Utilize the GetTickCount64 function when transitioning to .NET 4.0

After switching from VS2008 to VS2012 and updating all my code to .NET Framework 4.0, I needed to ensure compatibility with Windows XP. In my solution with multiple projects, most are in VB while one is in C++ for making unmanaged calls to DDE commands and ...

Unable to view Google Map markers within my XPath elements while using Selenium?

Looking to extract data from a Google Maps applet. The specific page can be found here: You can click on items on the map to view displayed information. While typical Google Maps show marker elements, I cannot see them on the provided link when inspecti ...