How to get the values from ascx control to aspx page?

I'm using Microsoft Visual Studio 2005.  I'm trying get values from my user control (ascx) page to aspx (.aspx) page.  The values in the user control are the listbox controls, I would like to be able to loop thru the listbox from .aspx page to .ascx controls.

I saw some examples and try to follow the example that was posted, I got the error message of saying: "System.NullReferenceException: Object reference not set to an instance of an object."

What I have do wrong?

Here's my source code:
Declare:

Protected oProductListCtl As ProductListCtl

Dim cboSelProductList As ListBox
cboSelProductList = oProductListCtl.FindControl("cboSelectedProduct")
(it failed in here:System.NullReferenceException: Object reference not set to an instance of an object.)

For i = 0 To cboSelProductList.Items.Count - 1
       sSelValue = sSelValue & cboSelProductList.Items(i).Value & ","
Next

Your help will be greatly appreciated.
Annie
achen30Asked:
Who is Participating?
 
jagadeesh_motamarriCommented:
>>cboSelProductList = oProductListCtl.FindControl("cboSelectedProduct")
cboSelProductList = (ProductListCtl)oProductListCtl.FindControl("cboSelectedProduct")
...not sure..though
0
 
achen30Author Commented:
sorry I post in wrong topics. This should be in asp.net.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
achen30Author Commented:
I find out other way to work around this problem.
Thanks,
All
0
 
achen30Author Commented:
This is the way that I got around with this by using Property get and set:

Public Property ProductSelected() As String
            Get
                Dim i As Integer
                m_ProductSelected = ""
                For i = 0 To Me.cboSelectedProduct.Items.Count - 1
                    m_ProductSelected = m_ProductSelected & cboSelectedProduct.Items(i).Value & ","
                Next
                Return m_ProductSelected
            End Get
            Set(ByVal Value As String)
                m_ProductSelected = Value
            End Set
        End Property

Thanks,
Annie
0
 
jagadeesh_motamarriCommented:
u might want to post it in the cleanup area to get a refund...
0
 
jagadeesh_motamarriCommented:
:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.