locked
Closing a page on prompt in MSCRM RRS feed

  • Question

  • I have a popup confirmation screen which comes on the button click of a custom cancel button in MSCRM. i am facing an issue in that.

    -->When i click the Cancel_button, i will be checking some conditions and if the conditions passes i need to bring the popup confirmation screen which prompts me to confrim the deletion a record using a delete confirmation Ok and Cancel screen.

    -->If the condition is failing i need not show the screen at all,instead of that i will show a general alert box that the record cannot be cancelled.
    But the problem which i am facing is, even if the condition is failing, along with the alert i am getting that page loaded which asks the confirmation of delete record and if the condition is passed the popup is coming but its not closing after that.

    Any solution for this?


    sini_tg
    Tuesday, March 2, 2010 5:42 PM

Answers

  • the standard approach for javascript to close a page is something like

    window.opener = 'x';
    window.close();



    Personally, I would use client side ajax script in the CRM form to check if I need to display the popup to the user first. Then display the popup if needed otherwise show an alert message.

    The aspx page Cancel button will not post back and will just call a CloseWindow function in a script block added between the page's <head> tags.

    The OK button needs to postback to perform your actions so there are a couple of things you could do. You could register the startup script from within the Ok click event to close the window, after you've done your processing. You could also set a hidden form field value in the OK event and when the form reloads you could call a function on the body onload event that checks this value and then closes the form using the close window function mentioned earlier.

    You could even pass a value back to the crm form through the window.returnValue attribute before you close the aspx page.

    Let me know how you get on.

    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, March 2, 2010 10:55 PM
    Moderator

All replies

  • Can you copy this piece of your code here?
    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, March 2, 2010 6:38 PM
    Moderator
  • There are many functionalities which are included in the code so its bit long also.

    The scenario is. I am clicking on a button which i created in Quote page to cancel a quote dependign on certain conditions. When i click the button in CRM, the conditions will be checked in page load and if its passes i will have to show the ok/cancel pop-up window(which i have designed in asp.net). when i am clicking ok, its performing the deletion functionality and alerting me that "deletion is done". in this case the parent window(OK/Cancel) is still open. i want some code to close that window.

    Hope you got it now

    Thanks
    sini_tg
    Tuesday, March 2, 2010 6:43 PM
  • just an eg of my requirement.
    in this sample. when i am getting a OK/Cancel window when the page runs. when  i click Cancel, it will close the window. But when i click OK, i have given an alert to come, meanwhile i want the parent ok/cancel window to close of. how to implement that?

     

    protected void Page_Load(object sender, EventArgs e)

    {

     

     

     

    // to close the window on the cancel button click
    New_Button.Attributes.Add(

    "onclick", "javascript:closewin();"); }

     

    protected void Btn_OK_Click(object sender, EventArgs e)

    {

     

    ShowMessageBox(

    "result");

     

     

     

    }

     

    protected void ShowMessageBox(string message)

    {

     

    string sJavaScript = "<script language=javascript>\n";

    sJavaScript +=

    "alert('" + message + "');\n";

    sJavaScript +=

    "</script>";

     

    this.RegisterStartupScript("MessageBox", sJavaScript);

    }

    protected void New_Button_Click(object sender, EventArgs e)

    {

     

     

    //some code here
    }


    sini_tg
    Tuesday, March 2, 2010 7:05 PM
  • the standard approach for javascript to close a page is something like

    window.opener = 'x';
    window.close();



    Personally, I would use client side ajax script in the CRM form to check if I need to display the popup to the user first. Then display the popup if needed otherwise show an alert message.

    The aspx page Cancel button will not post back and will just call a CloseWindow function in a script block added between the page's <head> tags.

    The OK button needs to postback to perform your actions so there are a couple of things you could do. You could register the startup script from within the Ok click event to close the window, after you've done your processing. You could also set a hidden form field value in the OK event and when the form reloads you could call a function on the body onload event that checks this value and then closes the form using the close window function mentioned earlier.

    You could even pass a value back to the crm form through the window.returnValue attribute before you close the aspx page.

    Let me know how you get on.

    MSCRM Bing'd - http://bingsoft.wordpress.com
    Tuesday, March 2, 2010 10:55 PM
    Moderator