Tuesday, December 13, 2011

Using the Dialog framework in SharePoint 2010 – Part 4


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:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com