Reputation: 581
When I coded this ASP.NET page, I did it in one .aspx
file and included the include file with the following lines:
<!--#include file="DSN.inc"-->
<!--#include file="SQL.inc"-->
However, since moving to Visual Studio, I now have two files with the extensions .aspx
and .aspx.vb
. What is the proper way to include these files so I can use them throughout the project?
Upvotes: 1
Views: 1674
Reputation: 13600
I guess you're talking about transitioning from a classic ASP to ASP.NET webforms, in which case you should look into learning about custom controls. We don't "include" files in the old fashion like you're used to, but rather through these customizable controls which you can place on your page and interact with them.
Developing Custom ASP.NET Server Controls
Upvotes: 3
Reputation: 56769
As @walther mentions, the original code was probably Classic ASP, not ASP.NET. These are fundamentally different technologies. You can't (and shouldn't) simply drop code from one page into another in that way in ASP.NET.
Judging by the names of the include files DSN.inc
and SQL.inc
, they were probably handling the connection strings for all pages, which was a common paradigm for Classic ASP. In ASP.NET this would typically be handled by placing your connection strings in a config file and/or shared static class.
Web.config
<connectionStrings>
<add name="MyConnectionName"
providerName="System.Data.ProviderName"
connectionString="Valid Connection String;" />
</connectionStrings>
.aspx.vb
Protected Shared Function GetData() As List(Of MyType)
Dim cs as String = ConfigurationManager.ConnectionStrings("MyConnectionName")
' ... connect to DB and get data ...
End Function
In ASP.NET, you can place code inline with your markup (.aspx) page, but a better / more maintainable design is to separate the logic (code) from the display (markup). A good place to start for learning about ASP.NET is the official ASP.NET site.
Upvotes: 3