locked
Return value from modal dialog - refresh form RRS feed

  • Question

  • I have two custom buttons in the opportunity form, which opens a modal dialog form. Only one of the buttons are visible at the time determined by a boolean on the form. I control this in the onload-event of the form.

    In my ISV.config file have the following for one of the buttons:

    <Button Icon="/_imgs/ico_18_debug.gif" JavaScript="window.showModalDialog('/ISV/Test/SendApproveRequest.aspx?id='+crmForm.ObjectId+'&amp;typename='+crmForm.ObjectTypeName)" Url="/ISV/Test/SendApproveRequest.aspx" PassParams="1" WinParams="" WinMode="1">

    I've switched from using the Url attribute to the Javascript one, but now I'm not sure how to proceed. In the modal form I have two buttons, one that performs some server side action ("Ok") and one html/javascript ("Cancel"). If the Ok-button is pressed I end up changing the boolean attribute that determines what button is shown on the form, and it closes the window using this code:

    string script = "window.close();";
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CloseWindow", script, true);

    So by either combining these to or doing something else, is it possible to refresh the form when hitting the OK button in the modal dialog? If I hit the Cancel button I don't want to refresh the form.

    Friday, March 26, 2010 12:49 PM

Answers

  • just did some more research on this ..I guess you're using window.opener right? This doesn't work for windows
    opened using showdialog.

    You can pass the parent window as an argument and
    reference it that way. Something like:

    In the parent
    window.showModalDialog( 'modal_window.aspx', window, '' );

    Now In the popup
    var parentWindow = window.dialogArguments;

    Now after that you can call parentWindow.RefreshScreen(); method..

    hoe this helps...

    Friday, March 26, 2010 9:59 PM

All replies

  • If the Ok-button is pressed I end up changing the boolean attribute that determines what button is shown on the form

    this changing of boolean field will help you to refresh your screen using location.reload() in Onload event

    It will work perfect for your requirement.

    refer http://a33ik.blogspot.com/2009/05/page-refresh.html

    Regards
    Vinoth

    Friday, March 26, 2010 12:57 PM
  • I hope when you are hitting the "Ok" button you are changing the boolean field in the opportunity form inorder to decide which button should be displayed. Once the opportunity record is saved the timerHandler() function will be invoked and page will be refreshed.
    Friday, March 26, 2010 1:04 PM
  • I hope when you are hitting the "Ok" button you are changing the boolean field in the opportunity form inorder to decide which button should be displayed. Once the opportunity record is saved the timerHandler() function will be invoked and page will be refreshed.
    Friday, March 26, 2010 1:05 PM
  • Hi, see following example code..put the following code in form on load...

    RefreshScreen = function() { 
    //crmForm.detachCloseAlert(); 
    window.opener.location.reload(); 
    var currentUrl = window.location.href; i
    f (currentUrl.indexOf('#') > -1) { 
    currentUrl = currentUrl.replace('#', ''); 
    } 
    else { 
    currentUrl += '#'; 
    } 
    window.location.href = currentUrl; 
    }

     

    Now put following code in your custom Form OK Button click ..where you want to refresh Opp form..

     

    if (typeof window.opener.RefreshScreen == 'object') { 
    // function exists, so we can now call it 
    window.opener.RefreshScreen(); 
    } 

     

    Hope this helps...

    Friday, March 26, 2010 1:21 PM
  • Vinoth,

    that works, but it displayed a popup  - "page is trying to refresh. post blablablabla"... so not very nice. I might be able to correct this with trusted sites or something..I don't know. Also, a bit to much code I think...but I'll have to investigate more.

     

    MayankP,

    Got an error, 'window.opener is null or not an object'. I believe this has something to do with the ShowModalDialog function, but I'm not sure.

    Did it like this:

    string script = "if (typeof window.opener.RefreshScreen == 'object') { window.opener.RefreshScreen(); }window.close();";
    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(),
    "CloseWindow", script, true);

     

     

     

     

     

     

    Friday, March 26, 2010 2:22 PM
  • try window.parent instead if window.opener  and see if this works..

     

    Friday, March 26, 2010 2:29 PM
  • hmm..didn't work. I'll have to leave this topic open due to easter :)

     

    I'll try any other suggestion after easter if you got any...You've deployed this to a solution yourself??

    Friday, March 26, 2010 2:41 PM
  • well, it works for me may be becuase i am doing it with CRM Forms..my forms are CASE and Phone call..

    something like as follows

    http://chiragrdarji.wordpress.com/2007/03/10/call-parent-windows-javascript-function-from-child-window-or-passing-data-from-child-window-to-parent-window-in-javascript/

    it seems that you not able to access the parent from your model dialog...

    can you able to put debuuger on your model form and see which property you can access from the parent..

     

    Friday, March 26, 2010 2:48 PM
  • well, it works for me may be becuase i am doing it with CRM Forms..my forms are CASE and Phone call..

    something like as follows

    http://chiragrdarji.wordpress.com/2007/03/10/call-parent-windows-javascript-function-from-child-window-or-passing-data-from-child-window-to-parent-window-in-javascript/

    it seems that you not able to access the parent from your model dialog...

    can you able to put debuuger on your model form and see which property you can access from the parent..

     

    • Proposed as answer by Mayank Pujara Monday, March 29, 2010 3:01 PM
    Friday, March 26, 2010 2:50 PM
  • Popup is shown if any of fields or their properties are changed on a html form. What you could do is to call the save function of the crm form.

    parent.opener.crmForm.Save(); This will not show the popup message and users will not loose any changes they have made on the form.

     

     


    If this answers your question, please use the answer button and say so. | Anoop
    Friday, March 26, 2010 4:15 PM
  • just did some more research on this ..I guess you're using window.opener right? This doesn't work for windows
    opened using showdialog.

    You can pass the parent window as an argument and
    reference it that way. Something like:

    In the parent
    window.showModalDialog( 'modal_window.aspx', window, '' );

    Now In the popup
    var parentWindow = window.dialogArguments;

    Now after that you can call parentWindow.RefreshScreen(); method..

    hoe this helps...

    Friday, March 26, 2010 9:59 PM