Home All Groups Group Topic Archive Search About
Author
9 Dec 2005 7:19 PM
Joe
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,
--
Joe

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

Author
9 Dec 2005 7:27 PM
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

Show quote
"Joe" <joeherro@donotspam.yahoo.com> wrote in message
news:014054AA-6431-4DF1-9583-ADF078F37C89@microsoft.com...
> 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,
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
Author
9 Dec 2005 7:44 PM
Joe
Thanks,

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

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


Show quote
"RCS" wrote:

> 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
>
> "Joe" <joeherro@donotspam.yahoo.com> wrote in message
> news:014054AA-6431-4DF1-9583-ADF078F37C89@microsoft.com...
> > 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,
> > --
> > Joe
> >
> > VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation
>
>
>
Author
9 Dec 2005 7:29 PM
Phillip Williams
Dim UControl As AugmentedDropDownList=
CType(LoadControl("UserControls/AugmentedDropDownList.ascx"),
AugmentedDropDownList)

Show quote
"Joe" wrote:

> 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,
> --
> Joe
>
> VB.NET/C#/ASP.NET/ASP/VB/C++/Web and DB development/VBA Automation

AddThis Social Bookmark Button