Populating User Control

G

Guest

Hello All,

I have a UserControl wwhich consists of one Label and one DropDownList
control. I have written a Public methofd to allow me to set the Label's Text
property and populate the dropdownlist with listitems. Here's the code:

Public Sub PopulateDropDownList(ByVal ListCaption As String, ByVal
ListItems As XmlNode)
Label1.Text = ListCaption
Dim Items As XmlNodeList = ListItems.SelectNodes("Items/Item")
For Each Item As XmlNode In Items
Dim li As New ListItem
li.Value = Item.Attributes("id").Value
li.Text = Item.Attributes("value").Value
DropDownList1.Items.Add(li)
Next
End Sub

I would like to call this from my webform by writing:

Dim UControl As UserControl =
CType(LoadControl("UserControls/AugmentedDropDownList.ascx"), UserControl)

UControl.PopulateDropDownList("Recipient's Name:", RecipientNamesNode)

This doesn't work. The PopulateDropDownList doesn't appear in the
intellisense list. What appears in the list are the properties and methids
of a UserControl (as anyone would expect).

How can I do this? I know that it's possible; I just can't think of a way
how.

Does anyone know of a good online reference for coding UserControls?

TIA,
 
R

RCS

It looks like you need to Dim your UControl as the specific object you are
loading.. in other words:

Dim UControl As AugmentedDropDownList =
CType(LoadControl("UserControls/AugmentedDropDownList.ascx"),AugmentedDropDownList)

Because intellisense looks to see what kind of object you have loaded - and
it thinks you just loaded an object of type UserControl - and you need to be
clear that it is an object of type AugmentedDropDownList.

HTH
 
G

Guest

Dim UControl As AugmentedDropDownList=
CType(LoadControl("UserControls/AugmentedDropDownList.ascx"),
AugmentedDropDownList)
 
G

Guest

Thanks,

I love it when I miss the obvious.
--
Joe

VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation


RCS said:
It looks like you need to Dim your UControl as the specific object you are
loading.. in other words:

Dim UControl As AugmentedDropDownList =
CType(LoadControl("UserControls/AugmentedDropDownList.ascx"),AugmentedDropDownList)

Because intellisense looks to see what kind of object you have loaded - and
it thinks you just loaded an object of type UserControl - and you need to be
clear that it is an object of type AugmentedDropDownList.

HTH
 
Joined
Aug 19, 2009
Messages
1
Reaction score
0
My question is very similar to this situation

I am doing the same in c# but when I use this line
UserControls_FuelControl DeptFBOFuel = (UserControls_FuelControl)e.Item.FindControl("DeptFuelControl");

i get the error
The type or namespace name 'UserControls_FuelControl' could not be found (are you missing a using directive or an assembly reference?)


What could I be missing or doing incorrectly that it doesnt see the reference?
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top