Reputation: 319
In ColdFusion, I could create a page and reference it from other pages within the website by using the cfinclude tag.
I am using C# in Visual Studio 2010 - ASP.NET environment.
What is the equivalent of cfinclude in c#?
Upvotes: 0
Views: 262
Reputation: 20804
There is probably no equivalent to cfinclude in the .net framework. In ColdFusion, the included file has access to all the variables to the including file. For example
MainPage.cfm
<cfset myVariable = "Have a nice day">
<cfinclude template = "IncludedFile.cfm">
IncludedFile.cfm
<cfoutput>#myVariable#</cfoutput>
will display "Have a nice day".
I've only done a bit of .net stuff, but I have not seen anything where 1 file inherits variables from another.
That does not mean that you can't re-use code in .net. It just means that you have to do it another way.
Upvotes: 0
Reputation: 38820
C# uses assemblies to separate code. The essence being that you add the other assembly as a reference to your second project, and then as musefun states, use the using
keyword to "import" the relevant namespaces in to a particular .cs file.
Your question mentions pages. If you're using something like MVC with the razor syntax, you can use partial views to share html across multiple pages.
You can also compile razor views in to a dll and reference them that way (see RazorGenerator) - this enables you to share common views across multiple projects. Things such as jquery scripts and other common script files can also be shared by embedding them as resources within a shared library and writing some boilerplate code to redirect routes to virtual path providers - though that is perhaps beyond the scope of this question.
Upvotes: 2