I am unable to manipulate a User Control's Label controls from the host ASPX page. I am trying to create N-number of user controls and add it to my Host.aspx page. Any help woul be greatly appreciate

I am unable to manipulate a User Control's Label controls from the host ASPX page.  I am trying to create N-number of user controls and add it to my Host.aspx page. Any help woul be greatly appreciated.
My ASPX page looks like this.

Host.aspx.vb------------------------------------------->

Public Class Host
      Public Sub Service_Info()
            Dim objRLL As New ReplacementLostLicense

            While objReader.Read()
                Dim objUCTL As New myUserControl

                    If IsDBNull(objReader.Item("ServiceTypeCD")) = False And objReader.Item("ServiceTypeCD") = "DOCREP" Then
                        objRLL.DateMailed = objReader.Item("MailDt")
                        objRLL.ReturnToDDS_Dt = objReader.Item("ReturnToDDS")
                    End If
                End If

          objServiceCtl.DisplayData(Nothing, Nothing, objRLL)
            service_status_Holder.Controls.Add(objServiceCtl)

            End While
      End Sub
ENd Class

And MyUserControl.aspx.vb looks like this ------------------------->

Public Class myUserControl
 Public Sub DisplayData(ByVal objMVR3 As MVRData, ByVal objMVR7 As MVRData, ByVal objRLL As ReplacementLostLicense)
        If IsNothing(objRLL) = False Then
            lblRLLDateMailed.Text = objRLL.DateMailed
            lblRLLReturntoDDSDate.Text = objRLL.ReturnToDDS_Dt
        End If
End Class
courchjoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rodmjayCommented:
I am not entirely sure what this code is supposed to do, but here are a few ideas

dim objUCTL as new myUserControl <------- Where are you using this??
objServiceCtl <----------- Where are you instantiating this??


ovalsquareCommented:
It should be objUCTL.DisplayData(Nothing, Nothing, objRLL) instead of objServiceCtl.DisplayData(Nothing, Nothing, objRLL) as the former uses the name you gave to your newly instantiated user control/s.

Another point:

In Public Sub DisplayData(ByVal objMVR3 As MVRData, ByVal objMVR7 As MVRData, ByVal objRLL As ReplacementLostLicense) you aren't even using the first two parameters, and while it works to pass in your objRLL as ReplacementLostLicense, I would personally just set two ppublic properties (DateMailed and ReturnToDDS_Dt) in your user control and set those in your while loop like the following:

    While objReader.Read()
                Dim objUCTL As New myUserControl

                    If IsDBNull(objReader.Item("ServiceTypeCD")) = False And objReader.Item("ServiceTypeCD") = "DOCREP" Then
                        objUCTL.DateMailed = objReader.Item("MailDt")
                        objUCTL.ReturnToDDS_Dt = objReader.Item("ReturnToDDS")
                    End If
                End If
            service_status_Holder.Controls.Add(objServiceCtl)

            End While

Ted

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
courchjoAuthor Commented:
Sorry about that. The code does look like this. I cleaned up my code and removed all the other unessecary lines so that it can be understood easily.
What I am basically trying to do is create multiple instances of my user control within a while loop for each record in my DataReader. And pass in some data to my usercontrol as objects where that data is picked up and displayed in various Labels and Text boxes (No other complex controls used).  
The error i am getting is on my UserControl page where I am trying set a value for my label.
It says "Object reference not set to an instance of an object." It even shows breaks with the same msg when you did a
Response.write(objRLL.DateMailed)



Host.aspx.vb------------------------------------------->

Public Class Host
     Public Sub Service_Info()
            Dim objRLL As New ReplacementLostLicense

            While objReader.Read()
                Dim objUCTL As New myUserControl

                    If IsDBNull(objReader.Item("ServiceTypeCD")) = False And objReader.Item("ServiceTypeCD") = "DOCREP" Then
                        objRLL.DateMailed = objReader.Item("MailDt")
                        objRLL.ReturnToDDS_Dt = objReader.Item("ReturnToDDS")
                    End If
                End If

         objServiceCtl.DisplayData(Nothing, Nothing, objRLL)
            service_status_Holder.Controls.Add(objUCTL)

            End While
     End Sub
ENd Class

And MyUserControl.aspx.vb looks like this ------------------------->

Public Class myUserControl
 Public Sub DisplayData(ByVal objMVR3 As MVRData, ByVal objMVR7 As MVRData, ByVal objRLL As ReplacementLostLicense)
        If IsNothing(objRLL) = False Then
            lblRLLDateMailed.Text = objRLL.DateMailed
            lblRLLReturntoDDSDate.Text = objRLL.ReturnToDDS_Dt
        End If
End Class
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

ovalsquareCommented:
Please follow my instructions above. It should fix it.

Ted
courchjoAuthor Commented:
Thanks for the reply. I did make the changes. But the problem still persists.

Public Class Host
     Public Sub Service_Info()
            Dim objRLL As New ReplacementLostLicense

            While objReader.Read()
                Dim objUCTL As New myUserControl

                    If IsDBNull(objReader.Item("ServiceTypeCD")) = False And objReader.Item("ServiceTypeCD") = "DOCREP" Then
                        objRLL.DateMailed = objReader.Item("MailDt")
                        objRLL.ReturnToDDS_Dt = objReader.Item("ReturnToDDS")
                    End If
                End If

            objUCTL.DisplayData(Nothing, Nothing, objRLL)
            service_status_Holder.Controls.Add(objUCTL)

            End While
     End Sub
ENd Class

And MyUserControl.aspx.vb looks like this ------------------------->

Public Class myUserControl
 Public Sub DisplayData(ByVal objMVR3 As MVRData, ByVal objMVR7 As MVRData, ByVal objRLL As ReplacementLostLicense)
        If IsNothing(objRLL) = False Then
            lblRLLDateMailed.Text = objRLL.DateMailed
            lblRLLReturntoDDSDate.Text = objRLL.ReturnToDDS_Dt
        End If
End Class
ovalsquareCommented:
Do the following:

Dim objUCTL As myUserControl

           While objReader.Read()
                    If IsDBNull(objReader.Item("ServiceTypeCD")) = False And objReader.Item("ServiceTypeCD") = "DOCREP" Then
                         objRLL.DateMailed = objReader.Item("MailDt")
                        objRLL.ReturnToDDS_Dt = objReader.Item("ReturnToDDS")
                         objUCTL = New myUserControl
                        objUCTL.DisplayData(Nothing, Nothing, objRLL)
                        service_status_Holder.Controls.Add(objUCTL)
                    End If
                End If
            End While

Again, I would personally make it so that you have properties for your User control....
ovalsquareCommented:
courchjo,

May I ask why you gave a "C" for this answer? I provided exactly what was needed including the necessary code to fix the problem.

Ted
courchjoAuthor Commented:
Hi Ted,
It was some thing to do with the way I was passing my data to my control. And wasn’t an issue with the way I had instantiated the objects. I redid my control all over again and coded it from start. And the new control seems to be working fine.

And I took a bit of a different approach. I used the dataset and used the filter property within a loop rather than using the datareader to group by a specific column.
 
Anyway I really appreciate the tips you gave. And I did use properties like you suggested. And I am using my friends account. I am new to the forum. So wasn’t so sure about the points system.

Thanks
Jay
ovalsquareCommented:
Jay,

Thanks for responding. A couple notes:

1. Your code as originally posted would not work that way (at least past the first user control added to your placer).
2. As many use already posted answers to find answers to new questions (somebody may run into the same problem), it is always best to post the final answer for future reference
3. It's always best to put "Accepted Answer" next to the actual accepted answer.
4. You can always request a points refund in the event that your question was not answered, but of course, sometimes it's better just to give the points if you have received legitimate help that you used in reaching your solution.

Past that, hope you enjoy EE and good luck with your app.

Ted
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.