How to assign value to User Control?
-
my situation is ,i have a user control(uc.ascx) consists of one label. i would like add more than one of same user control to aspx page (show.aspx) during runtime. For example: at show.aspx.vb file for i as integer 0 to 3 .... 1. declare user control 2.assign value to the label of user control, (let say the assign value is james,brian, kelly) ... next so this for loop will declare three user control and assign the different value to the label. so, the output on the screen will be james ( from user control 1) brian ( from user control 2) kelly ( from user control 3) i have this concept , but i dun know how to code it , anybody can help me ? thanks !
Best regards, Chee ken
-
my situation is ,i have a user control(uc.ascx) consists of one label. i would like add more than one of same user control to aspx page (show.aspx) during runtime. For example: at show.aspx.vb file for i as integer 0 to 3 .... 1. declare user control 2.assign value to the label of user control, (let say the assign value is james,brian, kelly) ... next so this for loop will declare three user control and assign the different value to the label. so, the output on the screen will be james ( from user control 1) brian ( from user control 2) kelly ( from user control 3) i have this concept , but i dun know how to code it , anybody can help me ? thanks !
Best regards, Chee ken
-
at user control file: Public Function GetLabelText() As Label Return Label1 End Function at aspx.vb Dim a As uc a = New uc a.GetLabelText.Text = "testing" Panel1.Controls.Add(a) then the page display this error message : Object reference not set to an instance of an object.
Best regards, Chee ken
-
at user control file: Public Function GetLabelText() As Label Return Label1 End Function at aspx.vb Dim a As uc a = New uc a.GetLabelText.Text = "testing" Panel1.Controls.Add(a) then the page display this error message : Object reference not set to an instance of an object.
Best regards, Chee ken
-
Normally, you would just make the property text, there's no reason to show the entire label.
-
'Public Property GetLabel() As String ' Get ' Return Label1.Text ' End Get ' Set(ByVal value As String) ' label1.text = value ' End Set 'End Property if i use this property set, also cause the same error page.
Best regards, Chee ken
-
It seems like you didn't place this into the user control. Then add an accessor in the page.