If you have not gone through Part-1 to Part-3 of this
series, I would recommend you reading them first and then continue reading from
here on.
In this post, we are going to see how we can pass
parameters to a parent page from where we have opened up the model dialog.
We take the same example that we have in our previous
post. I am not going to rewrite the entire code and pages. You can have a look
at previous posts to gain the insight of it.
Open your aspx page and change the button click
functionto following. As you can see we have declared an array of result and we
have passed name and value pair of parameter values in it and then passed the
entire results array as an object to our window.frameElement.commitpopup
method.
<script language="javascript" type="text/javascript">
function OkButtonClicked() {
var results = {
message: "Custom message from a custom dialog page",
passedvalue : "yes"
};
window.frameElement.commitPopup(results);
}
</script>
So when the page is closed, we can now retrieve these
parameters in the parent page. We can do so in following way.
Change the function on parent page code to this.
function FunctionToCall(dialogResult, returnValue) {
if (dialogResult == SP.UI.DialogResult.OK) {
SP.UI.Notify.addNotification('OK was clicked' + ' \n Message : ' + returnValue.message.toString() + '\n passed value : ' + returnValue.passedvalue);
}
if (dialogResult == SP.UI.DialogResult.cancel)
SP.UI.Notify.addNotification('Cancel was clicked!');
}
What we are doing here is we get the returnvalue as
results and can access the parameters as a property.
And when you build and deploy the solution and check,
you get the result like this.
Rear Part-5 for further reading.
No comments:
Post a Comment