Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Administrators
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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."

 

????????????????????????????????????????

Posted

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

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...