CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2006
    Posts
    216

    How to close ASP.net form from server side

    I have an ASP.net application. The server side code is in C#. There is a button on the form. When that button is clicked, then a server side code should be executed and then the page should close.

    When I write the code to close the page in .aspx file (by handing OnClick event) then the page closes even before the server side code can run.

    I want that the server side code (for the button click handler) should first finish and then the page should close.

    How to do that? Is there any way I can write code on server sid (in C#) to close the form?

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: How to close ASP.net form from server side

    Code:
    protected void btnClose_Click(object sender, EventArgs e)
    {
        Response.Write("<script language='javascript'>window.open('','_self',''); window.close();</script>");
    }
    this will also suppress the "an application is trying to close this window. Do you want to close it?" message.
    ===============================
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured