0

Hello all I have 3 webforms where it will open different forms on each click of button on the form, as I am not able to paste the code here I am writing up the fiddle here. So ideally on saving the content from form3 I Would like to pass it to form2 text box

Attaching the visual studio code from my drive

https://drive.google.com/file/d/18gpxfwRYkrRP1TituHNheH6Z_-rShTJB/view?usp=sharing

// WebFrom1 button click
function OpenUrl() {
  PopupItem("/WebForm2.aspx", '', 1150, 750, 'n', true);
}

// WebFrom2 button click
function OpenDialog() {
  PopupItemModal("WebForm3.aspx", '', 250, 250, false);
}

if (!window.showModalDialog) {
  window.showModalDialog = function(arg1, arg2, arg3) {

    var w;
    var h;
    var resizable = "no";
    var scroll = "no";
    var status = "no";

    // get the modal specs
    var mdattrs = arg3.split(";");
    for (i = 0; i < mdattrs.length; i++) {
      var mdattr = mdattrs[i].split(":");

      var n = mdattr[0];
      var v = mdattr[1];
      if (n) {
        n = n.trim().toLowerCase();
      }
      if (v) {
        v = v.trim().toLowerCase();
      }

      if (n == "dialogheight") {
        h = v.replace("px", "");
      } else if (n == "dialogwidth") {
        w = v.replace("px", "");
      } else if (n == "resizable") {
        resizable = v;
      } else if (n == "scroll") {
        scroll = v;
      } else if (n == "status") {
        status = v;
      }
    }

    var left = window.screenX + (window.outerWidth / 2) - (w / 2);
    var top = window.screenY + (window.outerHeight / 2) - (h / 2);
    var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    targetWin.focus();
  };
}

function isNumericValue(src, isFloat, isSigned) {
  var validChars;
  var ch;
  var bResult = true;

  if (isFloat && isSigned)
    validChars = "-0123456789.";
  else if (isFloat && !isSigned)
    validChars = "0123456789.";
  else if (!isFloat && isSigned)
    validChars = "-0123456789";
  else
    validChars = "0123456789";


  if (src.length == 0) return false;
  for (i = 0; i < src.length && bResult == true; i++) {
    ch = src.charAt(i);
    if (validChars.indexOf(ch) == -1)
      bResult = false;
  }
  return bResult;
}

function isNumeric(src) {
  return isNumericValue(src, false, true);
}

function isNumeric(src, isSigned) {
  return isNumericValue(src, false, isSigned);
}

function PopupItem(url, id, width, height, type, isResizable, scrollbars) {
  if (!id) {
    id = 'new';
  }
  if (id != 'new') {
    url = url + id;
  }
  if (!width || isNaN(Number(width) || width == 0)) {
    width = window.document.body.clientWidth;
  }
  if (!height || isNaN(Number(height)) || height == 0) {
    height = window.document.body.clientHeight;
  }
  if (!type) {
    type = new Date().getTime();
  }

  // Catch too big
  if (width + 12 > screen.availWidth) {
    width = screen.availWidth - 12;
  }
  if (height + 50 > screen.availHeight) {
    height = screen.availHeight - 50;
  }

  // Get the position for the new window
  var left = 0
  var top = 0;
  if (window.opener != null) {
    // Gets the center of the opener
    var centerX = (window.screenLeft - 4) + (document.body.offsetWidth / 2); // - 4 for the width of the window border
    var centerY = (window.screenTop - 23) + (document.body.offsetHeight / 2); // - 23 for the height of the chrome

    // Center to opener
    left = parseInt(centerX - (width / 2));
    top = parseInt(centerY - (height / 2));
  } else {
    // center to screen
    left = (screen.availWidth - 12 /* 12 pixels for the Border */ - width) / 2;
    top = (screen.availHeight - 50 /* 50 pixels for the Task Bar */ - height) / 2;
  }

  // Catch when off screen
  if (left + width + 12 > screen.availWidth) {
    left = screen.availWidth - width - 12;
  }
  if (left < 0) {
    left = 0;
  }
  if (top + height + 50 > screen.availHeight - 29) { // add 50 for Task Bar (29) and status bar (21)
    top = screen.availHeight - height - 29 - 21;
  }
  if (top < 0) {
    top = 0;
  }

  var qualifiedType;
  if (isNumeric(type)) {
    qualifiedType = type + '_' + id;
  } else {
    qualifiedType = type;
  }

  var specs = 'toolbar=no,status=no,height=' + height + ',width=' + width + ',left=' + left + ',top=' + top + ',resizable=' + ((isResizable == true) ? '1' : '0');
  if (scrollbars) {
    specs += ',scrollbars=yes';
  }

  var newWindow = window.open(url, qualifiedType, specs);
  return newWindow;
}

function PopupItemModal(url, id, width, height, type, isResizable) {
  if (!id) {
    id = 'new';
  }
  if (id != 'new') {
    url = url + id;
  }
  if (!width || isNaN(Number(width) || width == 0)) {
    width = window.document.body.clientWidth;
  }
  if (!height || isNaN(Number(height)) || height == 0) {
    height = window.document.body.clientHeight;
  }

  // Catch too big
  if (width + 12 > screen.availWidth) {
    width = screen.availWidth - 12;
  }
  if (height + 50 > screen.availHeight) {
    height = screen.availHeight - 50;
  }

  // Get the position for the new window
  var left = 0
  var top = 0;
  if (window.opener != null) {
    // Gets the center of the opener
    var centerX = (window.screenLeft - 4) + (document.body.offsetWidth / 2); // - 4 for the width of the window border
    var centerY = (window.screenTop - 23) + (document.body.offsetHeight / 2); // - 23 for the height of the chrome

    // Center to opener
    left = parseInt(centerX - (width / 2));
    top = parseInt(centerY - (height / 2));
  } else {
    // center to screen
    left = (screen.availWidth - 12 /* 12 pixels for the Border */ - width) / 2;
    top = (screen.availHeight - 50 /* 50 pixels for the Task Bar */ - height) / 2;
  }

  // Catch when off screen
  if (left + width + 12 > screen.availWidth) {
    left = screen.availWidth - width - 12;
  }
  if (left < 0) {
    left = 0;
  }
  if (top + height + 50 > screen.availHeight - 29) { // add 50 for Task Bar (29) and status bar (21)
    top = screen.availHeight - height - 29 - 21;
  }
  if (top < 0) {
    top = 0;
  }

  var args = {
    opener: self,
    window: window
  };

  var newWindow = window.showModalDialog(url, args, "dialogHeight:" + height + "px;dialogWidth:" + width + "px;dialogTop:" + top + "px;toolbar:no;status:no;help:no;resizable:yes;scroll:no");

  return newWindow;
}
--Web From1

<input type="button" onclick="OpenUrl();" value="Open" />
<br/>
// WebForm2
<input type='text' id='fromModal' />
<input type="button" onclick="OpenDialog();" value="Open" />
<br/>
// WebForm3
<input type='text' id='txtName' />
<input type="button" onclick="Save();" value="Save" />

-- On form3 save I would like to pass that value to form2
Developer
  • 8,228
  • 37
  • 122
  • 230
  • They are all part of the same page. – mplungjan Aug 14 '20 at 11:16
  • Nope, I attached the solution. All are 3 different pages – Developer Aug 14 '20 at 11:20
  • Does this answer your question? [Javascript; communication between tabs/windows with same origin](https://stackoverflow.com/questions/2236828/javascript-communication-between-tabs-windows-with-same-origin) – mappie Aug 14 '20 at 11:22
  • Normally in a SPA, the pages are all part of the same physical html page. In any case you can use sessionStorage – mplungjan Aug 14 '20 at 11:27
  • I tried something which looks a fit for me but couldn't https://jwcooney.com/2014/07/22/showmodaldialog-how-to-run-a-function-on-the-parent-page/ – Developer Aug 14 '20 at 11:33

0 Answers0