Link to home
Start Free TrialLog in
Avatar of courchjo
courchjo

asked on

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
SOLUTION
Avatar of rodmjay
rodmjay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of courchjo
courchjo

ASKER

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
Please follow my instructions above. It should fix it.

Ted
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
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....
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
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
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