473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
2 972
"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
* "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Asp Help | last post by:
I'm working on a ASP applicatition to create Windows 2000 users. Because I don't want everybody to have access to the site I've changed te security in IIS 5.0 which runs on a windows 2000 Sp4...
2
by: Stephen | last post by:
Hey everyone. I was wondering if someone could help me with a small problem. I have designed a user control and I would have inserted it on a aspz page (WebForm1). The User control is being used to...
36
by: danielx | last post by:
At first I was going to post the following: <!-- beginning of my original post --> I just discovered the inspect module, which contains the isfunction and ismethod functions. For some reason,...
0
by: tshad | last post by:
I am trying to access a method from outside my User Controls and am getting an error: Compiler Error Message: BC30456: 'FillGrids' is not a member of 'System.Web.UI.Control'. I have the...
0
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page...
5
by: Earl | last post by:
I need to call a method on an owned child form, and am wondering if the best way of doing this is to capture the Closing event of the form that passes control back to the form where I have the...
7
by: Sin Jeong-hun | last post by:
I've using thread a lot in C#, but all of them were just single method with no return value or paramenters. It may sound bizarre but, can't it be a class? I'm writing an Windows application that...
14
by: Doogie | last post by:
If I run this code below in ASP.NET 2.0 it fails with an "Object Required" error and I have no idea why. Could someone tell me why this is failing? Then if I can get an answer to that, I would...
1
by: Sylvie | last post by:
I have an Aspx page (Name:"PG") (Contains "UC") and an Ascx Usercontrol (Name:"UC") (Contains "AspxGrid1") I wanna expose Aspxgrid1.rowchanged event to Aspx Page, when user vhanges or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.