Reputation: 37
I have an assignment where I have to use c# and vb in the same project. After searching it seemed a website would be best for this in visual studios and it had been going relatively well. I ran into a problem when I was asked to have a label and a button. The Button is suppose to use vb code and the label is suppose to use c#. My initial response was to create two aspx pages and add the button to one and the label to the other and then no problems really came up. However I'm wondering if it's possible to use the same aspx page for both items and still have the vb coded button and c# coded label? If it is possible how do you do that sort of thing?
All insight is appreciated, thanks.
Upvotes: 2
Views: 224
Reputation: 12596
A single project cannot contain code from more than 1 language. A solution can contain multiple projects. Each project can use any language that is available to you, so you can have a solution with multiple languages, but within a single project, you can only have 1 language.
Upvotes: 1
Reputation: 900
It is not clear what do you mean by The Button is suppose to use vb code
. Does it mean that event handler for your button is written in VB.NET
or it is written in VB.NET
itself? Respectively for your C#
label. If you want to use these languages to write one *.aspx
answer is no. If these button and label are just custom controls written in VB.NET
and C#
answer is yes and check Servy
's answer.
Upvotes: 0
Reputation: 203802
You'll want to use a UserControl
. The user control can be written in either C# or VB, and then it can be added to an application page that's coded in the other language. When using a User Control, from the outside, you don't need to know if it was written in C# or VB, and it's designed to go into a page and play nicely with other controls, so you don't need to try to figure out how to combine two pages together in the browser.
Upvotes: 3