joshuaand Posted February 11, 2004 Posted February 11, 2004 HI, Ok I think this is a stupid question but I will ask anyways. In Previos versions of ASP, Ihave always used the <include statement to include files, mainly these files were code libraries, files like all my database functions, etc. So I want to do this in ASP.NET, all the files will be are code libraries, functions and subs that I will add and use in each page. My question is how do I achieve this? I read about the acsx extension was of including, but this creates a usercontrol, not what I want? Do I have to compile a DLL to get this to work? If so how? Thankyou very much You Help is Appreciated Joshua Quote
Administrators PlausiblyDamp Posted February 11, 2004 Administrators Posted February 11, 2004 Pure code libraries can be compiled into a dll that can be shared between multiple applications. User controls can be a good replacement for include files when you need to share parts of the UI between multiple pages in the same app. More complex functionality & UI could be compiled into a Custom Web control. Could you give a bit more details about what you need to do? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joshuaand Posted February 11, 2004 Author Posted February 11, 2004 Coe Library Hi, All I want is to include custom functions and subs into a common file, then share these between pages, they will include no user interface, just some functions like database calls, common mathematical routines etc. Not quite sute on the approach, I have strong .NET skills, just not around ASP.NET. Any Help is appreciated. ------------------------------------------------------------------------- Ok This is what I want to do for example: include these three functions (IN A SEPERATE FILE): public function getCheckbox() Dim theCheck as string theCheck = "<input type=""checkbox"" name=""test"" value="""">Test" return theCheck end function public function getRadioButton() Dim theCheck as string theCheck = "<input type=""radio"" name=""test"" value=""1"">Test 1" return theCheck end function Then On my ASPX page call it like: <html> <head> <title>Untitled</title> </head> <body> <Form> Check: <%=getCheckbox()%> Radio: <%=getRadioButton()%> </form> </body> </html> Any Help is appreciated! Thanks Josh Quote
*Experts* Bucky Posted February 11, 2004 *Experts* Posted February 11, 2004 Put the functions inside a class, and declare the functions as Shared. Then you can use them without having to declare an instance of the class. So, here's your code... Public Class Whatever Public Shared Function Something() As String ' Something End Function End Class And here's the HTML: <%=Whatever.Something()%> The <% %> code blocks don't even need to be within the <form> tag. Also, if this is all you're doing with them I suggest you use a Label control and set its Text property in the Load event of the Page, instead. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
joshuaand Posted February 11, 2004 Author Posted February 11, 2004 Thanks Hi, Thanks for the reply, I pretty much thought thats what I had to do, how do I include that dll into the page though? Thanks Joshua Quote
*Experts* Bucky Posted February 11, 2004 *Experts* Posted February 11, 2004 You don't need to include the DLL; if the code file is in the same project, the code will compile right into the app and you can use it. Another thing I forgot to point out is that you might need to fully qualify the function by including its namespace, also. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
joshuaand Posted February 12, 2004 Author Posted February 12, 2004 I Give Up! Hi, I still cant get it working, I have looked at other sites and this is what I currently have: MY class Module: (Created with visual studio as a Class Library, project called KIF., compiled to dll, and dll placed in bin directory on webserver) Imports System Imports System.Data.SqlClient Namespace KIF Public Class commonFunc Public Shared gDBConn As New System.Data.SqlClient.SqlConnection Public Shared Sub createDBConnection(ByVal ConnSTR As String) Try gDBConn.ConnectionString = ConnSTR Catch ex As Exception End Try End Sub End Class End Namespace This is the aspx page: <%@ Import Namespace="KIF" %> <script runat="server" language="vbscript"> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim CommonFunctions as New commonFunc CommonFunctions.createDBConnection("connstr") end Sub </script> <html> <head> <title>Untitled</title> </head> <body> test </body> </html> I Get The error "Type 'commonFunc' is not defined." ???????????????????????????????????????? Quote
joshuaand Posted February 12, 2004 Author Posted February 12, 2004 Figured It Out Hi, I figured it out, I needed: <%@ Import Namespace="KIF.KIF" %> instead of: <%@ Import Namespace="KIF" %> Is there anyway to remove the project name from the reference? thanks josh Quote
*Experts* Bucky Posted February 12, 2004 *Experts* Posted February 12, 2004 Well if the project name and the namespace the class is in should be the same, then just remove the namespace daclaration from the code file and the class will be in your project's namespace, KIF. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
joshuaand Posted February 12, 2004 Author Posted February 12, 2004 Thanks! Thanks for that, I still have a bit of learning to do then hey! I appreciate your help! Thanks Joshua Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.