Closing a Web Form using Visual C#

I am doing an assignment for a class where I create a web form and one of the buttons in it has to close the form. I am using Visual Studio .NET 2003 and Visual C# to do this. I can't find any method or property on how to do this. I tried this.Close() and it came back with an error. Does anyone have any code sample or know the method on how to have a button close the form


Answer this question

Closing a Web Form using Visual C#

  • Jim Kat

    This was the error and the part of the code where it happened:

    private void btnExit_Click(object sender, System.EventArgs e)

    {

    this.Close();

    }

    c:\inetpub\wwwroot\HMWK1\Diner.aspx.cs(74): 'HMWK1.WebForm1' does not contain a definition for 'Close'


  • jiny

    hi,

    yes What THELOTUs said is true , i just wanted to add something c# or vb is languages that work in the server doesn't have anything to do with the client computer to do something in the client computer you have to use javascript something like that

    <form>
    <input type="button" value="Close" onClick="window.close()">
    </form>

    hope this helps



  • ThePope

    Web forms does not work this way. If you want to close a popup, you will have to use javascript.

  • Phil M

    What is the error this.Close() is the appropriate way to close a Form.

  • Closing a Web Form using Visual C#