RadhaKrishnaKiJaya
asked on
Close a window in C#
Hello Experts,
In ASP.NET and C#, I am trying to close a window if there is no error in the form. If error exists, I don't want to close it. Is there a way?
Thank you in advance.
In ASP.NET and C#, I am trying to close a window if there is no error in the form. If error exists, I don't want to close it. Is there a way?
Thank you in advance.
ASKER
Hello AndyAinscow,
Thank you for your reply. I have btnModify_Click event. Inside it I do all kind of validations. I want to close the form if everything is valid. Otherwise I want to leave the form as it is. I have already tried this.Close(). But it does not compile.
Thank you!
Thank you for your reply. I have btnModify_Click event. Inside it I do all kind of validations. I want to close the form if everything is valid. Otherwise I want to leave the form as it is. I have already tried this.Close(). But it does not compile.
Thank you!
>>But it does not compile.
What is the compile error? Can you post the code and indicate the line(s) the compiler objects to.
What is the compile error? Can you post the code and indicate the line(s) the compiler objects to.
ASKER
Error 92 'ProjectName.ProgramName' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'ProjectName.ProgramName' could be found (are you missing a using directive or an assembly reference?)
ASKER
Hey Andy, It is already 2:00am. I will reply you back in the morning. Thank you!
OK, no problems.
Are you running this code on a form - Close is a method a Form would have built in (but not some other class in general).
Are you running this code on a form - Close is a method a Form would have built in (but not some other class in general).
ASKER
Yes, I am running in a Form.
Please post the code - that compile error doesn't make sense
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Since I did find any better solution, I need to close this question.
if(NoErrorOnForm())
this.Close();
Should close the form running the above code. You would need to code the NoErrorOnForm function yourself to check for an error, it should return true if everything was OK.