By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

How to add a method to a user control and use it in another

P: n/a
I need to add a method to a user control that can be called from another
usercontrol. Adding the method is not difficult and its already done.
However, the problem is that the method is not available from the second
user control.

For simplicity, here is the basic method:

Public Function ChangePaletteData(ByVal p_DataType As String) As Integer

me.lblPaletteName.text = p_DataType

' more code'
End Function

This method can not be seen from outside this user control. Is this
expected behavior? If so, why can I see a property I created outside of it,
but not the method?

Any help would be appreciated.

Luis Barnes
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"USNET" <lu*********@fuse.net> wrote in
news:#s**************@TK2MSFTNGP10.phx.gbl:
This method can not be seen from outside this user control. Is this
expected behavior? If so, why can I see a property I created outside
of it, but not the method?


You need an instance of the control to access the method.

If you wish to call a method from anywhere in the application without an
instance (or reference) to the control, you can created a Shared Function
(add the keyword SHARED to the function declaration).

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 20 '05 #2

P: n/a
* "USNET" <lu*********@fuse.net> scripsit:
I need to add a method to a user control that can be called from another
usercontrol. Adding the method is not difficult and its already done.
However, the problem is that the method is not available from the second
user control.

For simplicity, here is the basic method:

Public Function ChangePaletteData(ByVal p_DataType As String) As Integer

me.lblPaletteName.text = p_DataType

' more code'
End Function

This method can not be seen from outside this user control. Is this
expected behavior? If so, why can I see a property I created outside of it,
but not the method?


You will have to instantiate the usercontrol. Let's assume that the
name of the usercontrol class is 'UserControl1', then you will need this
code:

\\\
Dim foo As New UserControl1()
foo.ChangePaletteData(...)
///

If your reference is stored in a variable of type 'Object' or
'UserControl', for example, you will need to cast:

\\\
DirectCast(goo, UserControl1).ChangePaletteData(...)
///

BTW: Don't use the 'p_*' prefix for method parameters ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.