locked
Cannot to prompt message and close pop-up after saving data RRS feed

  • Question

  • Hello,

    Program description:
    When user input data and click Add button, the current add button is disabled and it trigger another hidden add button event to save data to database

    After data was saved, it will prompt "save successfully" message and close the current pop-up window

    Problem:
    After data was saved, it can't prompt message and close the pop-up

    ------------------------------------------------

    Here is my code:

    1. Function to hide hidden add button and add onclick script to add button in Page_Load event

    public void SetForm()
    {
      btnHiddenSave.Attributes.Add("style", "display:none");

      btnSave.Attributes.Add("onclick", "document.getElementById('" + btnSave.ClientID +
      "').disabled=true;document.getElementById('" + btnHiddenSave.ClientID + "').click();");
    }

    2. Function to prompt "save successfully" message and close the pop-up window

    public void ShowMessageAndCloseWindowByCode(string messageKey, Page page)
    {
      page.ClientScript.RegisterStartupScript(page.GetType(), "AlertMessage", "<script>function AlertMessageAndCloseWindow" +
      "() { " + "alert('" + ResourceManager.GetMessage(messageKey) + "');" + "window.close(); return false;}        setTimeout('AlertMessageAndCloseWindow" + "()',5);</script>");
    }

    Thanks and Regards,

    Tony

    • Moved by Anne Jing Wednesday, May 28, 2014 6:49 AM
    Tuesday, May 27, 2014 11:48 AM

Answers

  • Hi,

    For ASP.Net question, you should ask in forums of asp.net:

    http://forums.asp.net/

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Just Karl Wednesday, June 4, 2014 6:41 PM
    • Marked as answer by Just Karl Thursday, July 10, 2014 10:44 PM
    Wednesday, May 28, 2014 6:48 AM

All replies

  • You are mixing quite a bit of javascript with your C# code on backend. May I suggest just using jquery to do that? Would create a cleaner solution.

    Something like 

    $("<%= btnSave.ClientID %>").on('click', function(e) {
     var car = { Make: 'Audi', Model: 'A4 Avant', Colour: 'Black', Registered: 2013 };
    $.ajax({
                    type: "POST",
                    url: "/Receiver",
                    data: car,
                    datatype: "html",
                    success: function (data) {
                        alert("Success");
                    }
    });


    The other thing that I cannot see is when is the action of click being called?

    Tuesday, May 27, 2014 2:37 PM
  • Hi,

    For ASP.Net question, you should ask in forums of asp.net:

    http://forums.asp.net/

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Proposed as answer by Just Karl Wednesday, June 4, 2014 6:41 PM
    • Marked as answer by Just Karl Thursday, July 10, 2014 10:44 PM
    Wednesday, May 28, 2014 6:48 AM