Solved

Close a window in C#

Posted on 2016-09-14
10
25 Views
Last Modified: 2016-10-05
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
Comment
Question by:RadhaKrishnaKiJaya
  • 6
  • 4
10 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41799223
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
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 41799229
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41799230
>>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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:RadhaKrishnaKiJaya
ID: 41799238
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
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 41799245
Hey Andy,  It is already 2:00am.  I will reply you back in the morning.  Thank you!
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41799248
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
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 41799778
Yes, I am running in a Form.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41799786
Please post the code - that compile error doesn't make sense
0
 

Accepted Solution

by:
RadhaKrishnaKiJaya earned 0 total points
ID: 41807080
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
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 41829528
Since I did find any better solution, I need to close this question.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Search an image for an image 3 27
Hey!! 5 33
Following an example - Why do I need to click Save button twice? 3 25
Help with adding DLL file in Windows project 20 28
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question