0

Iam using two diffrenet pages.

Where First.aspx is having Submit button

when i click on this Submit it must change Labels text in Second.aspx

I tried using common JS file for both.

I have included JS in both First.aspx and Second.aspx.

my JS code for this simple functionlaity is

         StatusChecker.js // Common JS for both pages

        $(function () {

        $(".imgSubmit").click(function () { // imgSubmit is in First.aspx

        $(".lblStatus").text('This is New Status'); //lblStatus is in Second.aspx

         });
          });

Will this not workout???

If not how to fetch one pages control in other. Here i do not want to redirect after submitting or pass Query string. Thanks in advance.

Pink
  • 67
  • 1
  • 1
  • 9

2 Answers2

0

You can use HTML 5 for this. Following is not an exact code.

localStorage.yourValue = "something"; // Set your label value in 1st page in same JS


if(a != null)
{
     var a = localStorage.yourValue = "something";    
}
else
{
     alert(a); // Get the value
}
Anup
  • 9,396
  • 16
  • 74
  • 138
0

What you are trying to do is technically inpossible. You can´t create a click event on page A for page B, because they don´t know each other. You must do this by sending messages between the two pages. There two possible solutions to do this:

  1. Wrap the Second.aspx in an iframe in First.aspx. If you doing so, you can access the child document object from Second.aspx inside your JS code in First.aspx (so it´s possible to register an event on html elements in Second.aspx from JS context in First.aspx)
  2. Use localStorage or cookies that stores the message from First.aspx to Second.aspx. Just set the cookie in First.aspx and get it in Second.aspx. But remember that this technique only works in the same domain context due to security reasons. So, your page Fist.aspx and Second.aspx has to be stored on the same top-level domain. LocalStorage is a modern way of storing simple text files with an maximal set of bytes. This was shipped with HTML5, but it´s nearly the same as the old cookie technology, expect cookies got a lifetime, localStorage not.
alpham8
  • 1,314
  • 2
  • 14
  • 32