最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to close a Modal popup from ASP.NET button click? - Stack Overflow

programmeradmin0浏览0评论

Is there a way to close a modal popup from code-behind, through the click of a server-side button that's on the popup's aspx file ?

I have found code which can close a non-modal popup (i.e. one opened using window.open(...)) when user clicks a server-side ASP.NET button, but that code does not work on Modal popups ..

Also, no jQuery please, or any other 3rd party library ...

Also, the solution need only work on Internet Explorer, as that is the browser is that being used in our domain .. It's okay if the solution won't work on Chrome, Firefox, etc ..

Code used to raise the Popup:

<asp:Button ID="Button1" runat="server" Text="Button2" OnClientClick="basicPopup();return false;" OnClick="Button1_Click"/></td>

function basicPopup() 
{
    var strReturn = window.showModalDialog("TaxReportInputsForm.aspx", person,'status:no;dialogWidth:450px;dialogHeight:110px;dialogHide:true;help:no;scroll:yes');

    if(strReturn.okpressed == true)
    {
        ....
    }
    else
    {
        ....
    }
}

Note to all:

This is NOT a duplicate .. Believe me, I've searched far and wide .. All other questions are non-Modal popup related, which like I said, I already know how to close

Is there a way to close a modal popup from code-behind, through the click of a server-side button that's on the popup's aspx file ?

I have found code which can close a non-modal popup (i.e. one opened using window.open(...)) when user clicks a server-side ASP.NET button, but that code does not work on Modal popups ..

Also, no jQuery please, or any other 3rd party library ...

Also, the solution need only work on Internet Explorer, as that is the browser is that being used in our domain .. It's okay if the solution won't work on Chrome, Firefox, etc ..

Code used to raise the Popup:

<asp:Button ID="Button1" runat="server" Text="Button2" OnClientClick="basicPopup();return false;" OnClick="Button1_Click"/></td>

function basicPopup() 
{
    var strReturn = window.showModalDialog("TaxReportInputsForm.aspx", person,'status:no;dialogWidth:450px;dialogHeight:110px;dialogHide:true;help:no;scroll:yes');

    if(strReturn.okpressed == true)
    {
        ....
    }
    else
    {
        ....
    }
}

Note to all:

This is NOT a duplicate .. Believe me, I've searched far and wide .. All other questions are non-Modal popup related, which like I said, I already know how to close

Share Improve this question edited Jun 25, 2013 at 12:12 Ahmad asked Jun 25, 2013 at 11:57 AhmadAhmad 13.5k31 gold badges102 silver badges152 bronze badges 5
  • Please provide the code and html that was used to raise the modal popup? – Rohit Kiran Commented Jun 25, 2013 at 12:02
  • possible duplicate of How to close current tab in a browser window? – David Commented Jun 25, 2013 at 12:02
  • 1 This probably can't (and definitely shouldn't) be done from server-side code. But if the new window was opened from client-side code then it can also be closed from client-side code (as in the referenced question). – David Commented Jun 25, 2013 at 12:03
  • @RohitKiran, I've provided the raise code – Ahmad Commented Jun 25, 2013 at 12:13
  • Everyone: This is NOT a duplicate .. Believe me, I've searched far and wide .. All other questions are non-Modal popup related, which like I said, I already know how to close – Ahmad Commented Jun 25, 2013 at 12:14
Add a ment  | 

2 Answers 2

Reset to default 1

You should consider the ments of David. Well anyhow, you can add the window.close(); as said by @CodeMonkeyForHire and affix the following at the end of the click event by which you wish to close the popup.

Response.Write("<script language='javascript'>self.close();</script>");

This should work.

window.close();

Just return a script block with that in it.

发布评论

评论列表(0)

  1. 暂无评论