Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 34
  • Last Modified:

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.
0
RadhaKrishnaKiJaya
Asked:
RadhaKrishnaKiJaya
  • 6
  • 4
1 Solution
 
AndyAinscowCommented:
air code in C#:

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.
0
 
RadhaKrishnaKiJayaAuthor Commented:
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!
0
 
AndyAinscowCommented:
>>But it does not compile.

What is the compile error?  Can you post the code and indicate the line(s) the compiler objects to.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RadhaKrishnaKiJayaAuthor Commented:
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?)
0
 
RadhaKrishnaKiJayaAuthor Commented:
Hey Andy,  It is already 2:00am.  I will reply you back in the morning.  Thank you!
0
 
AndyAinscowCommented:
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).
0
 
RadhaKrishnaKiJayaAuthor Commented:
Yes, I am running in a Form.
0
 
AndyAinscowCommented:
Please post the code - that compile error doesn't make sense
0
 
RadhaKrishnaKiJayaAuthor Commented:
Andy,
Due to strict company policy in place, I will not be able to post my code.  If you have a sample program (could be small), please provide me.  Here is the JavaScript code I found and working.

string strScript = "window.close();";
ScriptManager.RegisterStartupScript(this, typeof(string), "key", strScript, true);

Thank you for your help!
0
 
RadhaKrishnaKiJayaAuthor Commented:
Since I did find any better solution, I need to close this question.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now