Donnerstag, 21. Oktober 2010

Mehrere SP.UI.ModalDialog.showModalDialog - CallBack

Wenn man mehrere SP.UI.ModalDialog.showModalDialog Fenster auf einer Seite platziert, ist es wichtig, dass die Callback Methoden unterschiedlich heissen. Ansonsten funktioniert immer nur ein Dialog Callback. Deshalb in den Properties des Dialogs immer einen anderen Methodennamen verwenden.

If you are using multiple SP.UI.ModalDialog.showModalDialog windows on your page, be aware to have different callback methods defined. Otherwise there will be just one callback working. Therefore set in the properties of your dialog always a different method.

Dialog 1:

function OpenDialog1()
{
var options1 = {
url: '/_layouts/MyDialog.aspx',
title: 'MyDialog',
allowMaximize: false,
showClose: true,
width: 400,
height: 400,
dialogReturnValueCallback: DialogCallback1 };

SP.UI.ModalDialog.showModalDialog(options1);
}

function DialogCallback1(dialogResult, returnValue) {
[Your code on callback]
}

Dialog 2:

function OpenDialog2()
{
var options2 = {
url: '/_layouts/MySecondDialog.aspx',
title: 'MySecondDialog',
allowMaximize: false,
showClose: true,
width: 400,
height: 400,
dialogReturnValueCallback: DialogCallback2 };

SP.UI.ModalDialog.showModalDialog(options2);
}

function DialogCallback2(dialogResult, returnValue) {
[Your code on callback]
}


Es existiert noch eine andere Schreibweise ->
There is also another way of defining the dialog ->

Dialog 1:

function OpenDialog1()
{
SP.UI.ModalDialog.showModalDialog(options);
var options1 = SP.UI.$create_DialogOptions();
options1.url = '/_layouts/MyDialog.aspx';
options1.width = 400;
options1.height = 400;
options1.allowMaximize = false;
options1.showClose = true;
options1.dialogReturnValueCallback = DialogCallback1;

SP.UI.ModalDialog.showModalDialog(options1);");
}

function DialogCallback1(dialogResult, returnValue) {
[Your code on callback]
}

Dialog 2:

function OpenDialog2()
{
SP.UI.ModalDialog.showModalDialog(options);
var options2 = SP.UI.$create_DialogOptions();
options2.url = '/_layouts/MySecondDialog.aspx';
options2.width = 400;
options2.height = 400;
options2.allowMaximize = false;
options2.showClose = true;
options2.dialogReturnValueCallback = DialogCallback2;

SP.UI.ModalDialog.showModalDialog(options2);
}

function DialogCallback2(dialogResult, returnValue) {
[Your code on callback]
}

2 Kommentare:

  1. bei der zweiten Schreibweise ist aber sicherlich das "SP.UI.ModalDialog.showModalDialog(options);" ganz zu Beginn falsch. Da gibts ja gar keine "options" und er würde zwei Dialoge öffnen :)

    AntwortenLöschen
  2. Stimmt. Danke für den Hinweis, habe dies angepasst.

    AntwortenLöschen