I made an application in c# and I want to load
that into a website that you can use, is it
possible to add it to .ASP without converting
everything by hand to .ASP?
Like you look at JAVA you can make a application
then turn it into a java applet... than you can
add it to a website... can I do the same with my
C# application?
Loading
Mahesh ChandPosted Oct 31, 2009, 7:16 AM
I am assuming your application is written in Windows Forms using C# language. That means, you created an Application using Visual Studio and it has bunch of Forms and controls. Now you want to run same application on the Web and thinking to convert it to ASP.NET.
To run any application in a Web Browser, it must be hosted in HTML. A Windows Forms does not have HTML in it so a Web Browser has no idea what to do with it.
In theory, you can run a Windows Form on the Web by using some tweaks (Host a Windows Form within a HTML page) but your application WILL NOT be efficient and WILL NOT work propertly and I consider it as a JUNK application. The reason is simple. ASP.NET and Windows Forms are two different technologies and purpose of both is different.
That said, you DO NOT have to use Silverlight to create a Web application. You need to create an ASP.NET application (also known as Web Forms application) and redo your work. It depends what version of .NET Framework and Visual Studio you are using. Silverlight and WPF and new ways to write Web and Windows applications using .NET 3.5 and 4.0.
There is no way direct way in Visual Studio that can import a Windows Forms application to a Web Forms (ASP.NET) application. However, you can direct use your C# code in ASP.NET as long as this code is generic to C# libraries not related to Windows Forms.
There are some third part tools out there that will do this conversion for you but not sure how good they are:
http://www.suite4.net/products/form.suite4.net/win-web-forms/default.aspx
theLizardPosted Oct 31, 2009, 8:27 PM
in a generic class with NO reference to windows forms or Web Controls just these
//using System;
//using System.Data;
//using System.Data.Sql;
//using System.Data.SqlClient;
//using System.Collections.Generic;
add the following shared function (will be used in both windows forms apps and web form apps)
public Object[] getListFromSource(Object[] sender)
{
genericClass1 q = new genericClass1();
Array.Resize(ref sender, 2);
sender[0] = "Hello";
sender[1] = "Hello There";
//get items from database or wherever
//database scenario using generic sql data access class
// Array.Resize(ref sender, 0);
//while (q.read())
// {
// Array.Resize(ref sender, sender.Length + 1);
// sender[sender.Length - 1] = q.get("fieldName");
// }
// tested loading from sqlexpress database in both apps.
return (sender);
}
create a new windows forms project and a new asp project then add this generic class to both
on your windows form add a combo box and a button, in the Button_Click event add the following
//a generic class that only has
//using System;
//using System.Data;
//using System.Data.Sql;
//using System.Data.SqlClient;
//using System.Collections.Generic;
genericClass1 q = new genericClass1();
//for test purposes create object array
//in real world you would resize array as items are added
Object[] p = new Object[2];
//get the data from, say a database and fill the object array. Note:
p= q.getListFromSource(p);
//add the object array to the combo box
c.Items.AddRange(p);
on the web form add a DropDownList and button and in the the button_click event add the following
genericClass1 q = new genericClass1();
//as there is no direct conversion from an object to ListItem, need a work around so create another generic class
// in the web app to do some conversions
webGenericClass2 cl = new webGenericClass2();
Object[] p = new Object[2];
//call the shared function to get data from database
p = q.getListFromSource(p);
//fill the web control with data after conversion from object to ListItems
ddl.Items.AddRange(cl.list(p)); //Note: there may be a more direct conversion...
in webGenericClass2 add the following function, this is write once use many
public ListItem[] list(Object[] sender)
{
ListItem[] j = new ListItem[sender.Length];
for(int i=0; i < sender.Count(); i++)
{
j[i] = new ListItem(sender[i].ToString());
}
return(j);
}
As you can see with a little effort it is possible to write code that can be used for both Windows Forms and Widows Web Forms
My tests have shown this to work, both combo box a dropdown list were filled with the same code.
No you cannot run a desktop app on a web browser same as you cannot run a web app without a web browser but you CAN write code that both can use with a little planning and lateral thinking, yes you will need to work around some problems but these are the mothers of invention and what can't be done one way can be done another we simply need to think outside the square.
I have given you a seed, now go and grow a forest
Jason MeyerPosted Oct 31, 2009, 1:40 PM
was just checking because converting a
application over to the web would be a pain.
On the other hand i could make a generic looking
app, for client-side display and just run the
application server side and so i would just have
to feed it whatever user info it needs, and then
throw out what it returns back to the client...
I guess thats a better idea then fully
redesigning a app.
Thanks for all the info.
Jason Meyer
theLizardPosted Oct 31, 2009, 4:20 AM
System.Web.UI.WebControls.DropDownList and System.Windows.Forms.ComboBox will be seen by this in code behind protected void ddlMenuHeadings_SelectedIndexChanged(object sender, EventArgs e) as being the same
DropDownList and ComboBox both have an Items member both add items by ?.Items.Add(item);
sender can be cast to DropDownList or ComboBox
ComboBox cb = (ComboBox)sender;
DropDownList dl = (DropDownList)sender;
So while your application does not allow you to do this because you have not planned for it does not mean that you cannot write web and forms applications that share common code.
the key is that you create classes that ARE generic AND include references for web controls AND windows forms. It won't be easy but it can be done.
It is possible that you CAN create a ASPX web form and a Windows form with comparable controls having the same events and methods, parse these to the generic class and bingo you have web app and forms app using the same code.
For your info I have been programming for 30 years from before you were born programming is NOT accepting limitations, if you can't do it one way you do it another, impossible is going to the moon without a rocket to get you there.
If you want to be good at programming you MUST NOT accept that things cannot be done. Open your minds, think outside the square you live in.
And by the way, after 30 years programming in languages you have never heard of I am still not an expert, there is always new ways of doing things my way, your way and his way is not the best way, there is always some one who comes up with a better way of writing code...
jingePosted Oct 31, 2009, 3:26 AM
Kirtan PatelPosted Oct 31, 2009, 3:16 AM
jingePosted Oct 31, 2009, 2:59 AM
Kirtan PatelPosted Oct 31, 2009, 2:19 AM
for example
if We Use Windows Form Message Box in Asp.net rather than showing message box on Client Side it Displays on the WebServer ..
jingePosted Oct 31, 2009, 2:14 AM
Kirtan PatelPosted Oct 31, 2009, 1:25 AM
its not possible by anyway dear .. because even if you try to implement this kind of functionality the code will not react with the client side and its only possible with very few controls what about others ????..
Silver light application Fully supports the Browser :)
jingePosted Oct 31, 2009, 1:20 AM
It's possible. In jave we have applet and host the applet in the website. In .NET, we can create a Windows Forms UserControl, and host it in the website.
Here is a blog with detail steps.
http://weblogs.asp.net/spano/archive/2007/09/19/hosting-a-windows-form-control-in-a-web-page.aspx
Jason MeyerPosted Oct 30, 2009, 2:30 PM
Guess i have to add all the buttons and list boxes, etc... to .asp and
copy and paste all the code files into it... kinda time consuming :(
Kirtan PatelPosted Oct 30, 2009, 11:20 AM
its not possible in C#
you have to create application in Silver light to get Windows Like Look
:)
if my answer helps you please check "Do you like this answer" :)