Accessing functions in dlls from code behind


shaun duke

I have been researching this over the last two days without success.

I have a number of ultility functions that I want to make available to
all pages. The pages will all be using code behind so my plan is to
create an assembly CommonFunctions.dll place it in the /bin folder for
the application and import the namespace into the code behind where

Here is an abstract of CommonFunctions.vb

Option Strict Off
Imports System etc etc etc

Namespace CommonFunctions
Public Class Functions

Inherits Page
Public Sub SetFocus(ByVal FocusControl As Control)

Dim ClientID As String = FocusControl.ClientID
Dim ScriptString as String = "<script
language='javascript'>document.getElementById('" & ClientID &
RegisterStartupScript("setFocus", ScriptString)

End Sub

End Class
End Namespace

This compiles correctly and I have no problem using the SetFocus
function from a aspx with no code behind using
<%@ import Namespace="CommonFunctions" %>

My problem comes when trying to use SetFocus in code behind script.
Even though I import the namespace I get the error BC30451: Name
'SetFocus' is not declared.

Thanks in advance



Karl Seguin

If this truly is a utility class, it really shouldn' tinheirt Page...

Public Class Functions
Public shared Sub SetFocus(ByVal controlClientId As string)
Dim ScriptString as String = "<script
language='javascript'>document.getElementById('" & controlClientId &
Page).RegisterStartupScript("setFocus", ScriptString)
End Sub
End Class

notice three things:
1 - I made the function shared...which means you can access it via
2 - I passed in a string instead of the control (all you are doing with the
control is getting the clientId, so why not just pass in the clientId??)
3 - Since I no longer inherit Page, I need to get the current page via
HttpContext.Current.Handler alternatively, I could pass the page as a 2nd



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question