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
 

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

Top