Thursday, 20 August 2009

Getting the dialog arguments passed into a web page modal dialog

This is especially useful if you use Microsoft CRM. Because it ties in very closely to how the entity forms and grid views communicate to custom web pages etc.

For example, in Microsoft CRM you can edit the ISVConfig to add a button to the toolbar for the entity grid. Set the WinMode=2 (2 basically means a modal dialog) to allow CRM to provide you with the selected entities. So how do we know what items were selected in the entity list? It passes us in a list of IDs as part of the window.dialogArguments.

So, how do we get access to this? Through javascript. Here's the steps:

1. Create the following javascript function (available from MSCRM help pages):

function loadSelectedListItems() {
  var sGUIDValues = "";
  var selectedValues;
  //Make sure window.dialogArguments is available.
  if (window.dialogArguments) {
    selectedValues = new Array(window.dialogArguments.length - 1);
  else {
  selectedValues = window.dialogArguments;
  if (selectedValues != null) {
    for (i = 0; i < selectedValues.length; i++) {
      sGUIDValues += selectedValues[i] + ",";
    document.getElementById('<%= winDialogArguments.ClientID %>').value = sGUIDValues;

2. Use this function as part of the onload of the body:
<body onload="loadSelectedListItems()">

3. Create a new holder object (in my example an asp textbox) in a hidden division on your form:
<div style="visibility: hidden">
   <asp:textbox id="winDialogArguments" runat="server" text="">

Job done. Just access the Text of the asp textbox server side on the next post back (e.g. click of an OK button) to get the list of IDs.


  1. Hello! This solution works under the ISV folder but if I put this in another folder like C:\Test\Mypages\Mypage.aspx The solution doesn't work. Do you know why??? Could you please help me with this?

  2. Interesting, never come across that before. Can you double check that WinMode="2" is set in the isvconfig. E.g.:

    <MenuItem Url="http://myservername/testing/Default.aspx" WinMode="2" PassParams="1">


    Also make sure it's a valid website you are pointing at. If you are getting a blank web page it may just be surpressing an error. Have you tried hitting the page directly via your internet browser?

    If the above doesn't work I can only presume it's some sort of security. If you add a virtual directory to the Microsoft CRM site pointing to your page and reference that instead does that fix the issue? For example:

    - In IIS right click Microsoft Dynamics CRM and create a virtual directory called "testing"

    - Point this to your folder with your website

    - In the ISVConfig point your menu button to this instead:

    <MenuItem Url="/testing/Default.aspx" WinMode="2" PassParams="1">

    Hope this helps.


Note: only a member of this blog may post a comment.