views:

1050

answers:

6

I have a main page and a details page.

The details page is a javascript popup invoked from the main page.

When the 'save' button is clicked on the details page, I want the main page to 'refresh.'

Is there a method of invoking a postback to the main page while also maintaining the save postback from the details page?

Edit - Using window.opener.location.reload(true) does work, but it prompts the user to resend information. This 'document.location.href = document.location.href;' does not work either because it clears the form on the main page.

A: 

Yes, you should be able to do target="_parent" on the link from your details page. You'll have to bind an event onto that to close the details page though but should get you started.

eg: <a href="mainPage.html" target="_parent">Save Details</a>

Jamie
Hrm... Not sure what you're trying to say. I don't want to close anything and yes, I am already saving from my details page. When the details page is saved, I simply want to refresh the main page. Perhaps you could explain yourself further.
A: 

You can access the parent window from the popup using some javascript with window.opener. From there you can use, for example, location.href to refresh the parent page. :)

Lucas
Yes, thank you. I will look into this.
A: 

I would recommend using a modal popup for the details page instead of opening another window through javascript. This will allow you to save everything on the same page and will give you more control

Considering your current situation I think you are going in the right direction. Try this out and see if it fits your needs.

window.opener.location.href='http://redirect.address';

Here is a similar question

jmein
An excellent idea, however, users compare details using the popup windows. i.e. They place various detail popup windows side by side and compare the details.
how many are they going to compare? If they are only going to be comparing two items then you could have the modal popup with one items showing and then allow the user to add another. You could then just split the modal down the middle with a line and show the corresponding data for the new item. Otherwise, you could use a repeater on the fields to be compared if there are more than two but this could get a little messy (running out of room on the page).
jmein
They can compare up to 6 details. You're correct there are ways of doing it modally, but for now, I will pursue another solution.
ah yeah I think you are going in the best direction then. good luck
jmein
A: 

I know you said you needed to do a postback, but I'll offer up this suggestion...

I would place an ajax updatepanel on the main page, and then allow the detail popups to update that. I'm not sure how much of a liking to microsoft ajax and the ajax control kit you have, but that would be my first approach.

Obviously I don't know the full scope, but I don't see the problem of the page asking for the user to resubmit the data going away and the page updating without some sort of JavaScript based solution.

MattK311
+1  A: 

For an updatepanel-free solution, you can have the popup return a value to a text field, and make that text field postback on change.

chris
A: 

If you need to refresh the page and keep the form data without resubmitting the POST, you may be able (depending of the size and complexity of your form data) to build a representation of the form state in JavaScript, store it in a cookie or the querystring, refresh the page by setting document.location.href, and then reload the data when the window loads.

Below is a rough version of this idea. This code along, with an onload wire-up, would go in the opener (the cookie handling methods would also need added). window.opener.refreshWithState() would be called from the popup.

(this version depends on inputs having unique IDs)

(function() {
  window.refreshWithState = function() {
    setCookie("state", buildState());
    document.location.href = document.location.href;
  };

  function handleWindowLoad() {
    var state = readCookie("state");
    if (state) {
      restoreState(state);
      eraseCookie("state");
    }
  }

  function buildState() {
    var i, elem, elems, key, val, stateParts = [];

    elems = document.getElementsByTagName('INPUT');
    for (i = 0; elem = elems[i]; i++) {
      switch (elem.type) {
        case "checkbox":
        case "radio":
          val = elem.checked ? 1 : "";
          break;
        case "text":
        case "hidden":
        case "file":
          val = escape(elem.value);
          break;
        default:
          continue;
      }
      stateParts.push('"' + escape(elem.id) + '":"' + val + '"');
    }

    elems = document.getElementsByTagName('SELECT');
    for (i = 0; elem = elems[i]; i++) {
      stateParts.push('"' + escape(elem.id) + '":"' + elem.selectedIndex + '"');
    }

    return '{' + stateParts.join(',') + '}';
  }

  function restoreState(state) {
    var key, elem, val;
    var stateObj = eval('(' + state + ')');

    for (key in stateObj) {
      elem = document.getElementById(unescape(key));
      if (!elem) {
        continue;
      }
      val = stateObj[key];
      if (elem.tagName == "SELECT") {
        elem.selectedIndex = val;
      }
      else if (elem.tagName == "INPUT") {
        switch (elem.type) {
          case "checkbox":
          case "radio":
            elem.checked = !!val;
            break;
          case "text":
          case "hidden":
          case "file":
            elem.value = unescape(val);
        }
      }
    }
  }
})();
Rojo