Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created an aspx project and added an existing PURE c# project. They are in one solution now. There is a button in aspx on which the c# form will open and run when clicked. I tried many things but none worked. Im not even sure if this is possible cuz some said its a mismatch thingy but some provided codes but didnt work. I just new in here, it would ve great if someone help.

What I have tried:

This is the closest one I tried but it only opened the cs code behind and not the design itself
Process.Start("c:\\somepath\\form.cs");


I tried this but it cause error could not find namespace sumtin like that.

C#projectname.Form1 f1 = new c#projectname.Form1();
f1.Show();

Im also dne adding references

Please help
Posted
Updated 10-Oct-17 7:39am

Try:
C#
form f = new form();
f.Show();
Where form is the name of the class (and normally matches the name of the file you put it in)
 
Share this answer
 
Comments
Member 13450685 7-Oct-17 21:05pm    
@OrginalGriff Thanks for answering but i got two errors, "The type or namespace Form1 could not be found (are you missing a using directive or an assembly reference??

The name of the c# class is
public partial class Form1 : Form
OriginalGriff 8-Oct-17 1:45am    
So look at the two files: What namespace is the code that tries to open the form in? What namespace is the form class definition in?
Richard Deeming 10-Oct-17 13:31pm    
That's not going to work in an ASP.NET application! :)
In an ASP.NET application, the C# code runs on the server. Even if you were able to start a new interactive process, or open a Windows Forms / WPF window, it would appear on the server where nobody would be able to see it.

It might appear to work when you debug your application in Visual Studio. But that's only because, in that specific instance, the server and client are the same computer. As soon as you deploy to a real server, you'll either get an exception telling you that the current process is not interactive, or your code will hang waiting for an administrator to close the thousands of hidden instances of your form.

And you can't launch your form from script running on the client either. Even if the client is running a supported operating system, and has the required version of .NET installed, websites cannot launch random programs, because that would be a security nightmare.
 
Share this answer
 
Comments
Karthik_Mahalingam 11-Oct-17 23:56pm    
5, exact

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900