You must Sign In to post a response.
  • Category: ASP.NET

    Close page after a button click

    i want to close my webpage when i clicking a button. using c#
  • #767322
    Hi,
    Try this:
    .aspx:

    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" / >

    .cs:

    protected void Button1_Click1(object sender, EventArgs e)
    {
    Response.Write("<script type='text/javascript'> window.returnValue = true;window.close();</script>");
    }

  • #767326
    Hi,

    Refer below..

    <script>
    function closeWindow() {
    window.close();
    }
    </script>
    <button onclick="closeWindow()">Close</button>


    Hope this will help you

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring

  • #767343
    Hi,

    In your design you make this javascript code and call this function in your server side code behind.


    function CloseWindow() {
    window.close();
    }


    and on cancel button click call the above function


    protected void btnCancel_Click(object sender, EventArgs e)
    {
    Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();");
    }


    Try something like above may be this may help you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments