Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to assign value to User Control?

How to assign value to User Control?

Scheduled Pinned Locked Moved ASP.NET
tutorialhelpquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheeken2u
    wrote on last edited by
    #1

    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

    E 1 Reply Last reply
    0
    • C cheeken2u

      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

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      What have you done so far? What part are you stuck on?

      C 1 Reply Last reply
      0
      • E ednrgc

        What have you done so far? What part are you stuck on?

        C Offline
        C Offline
        cheeken2u
        wrote on last edited by
        #3

        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

        E 1 Reply Last reply
        0
        • C cheeken2u

          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

          E Offline
          E Offline
          ednrgc
          wrote on last edited by
          #4

          Normally, you would just make the property text, there's no reason to show the entire label.

          C 1 Reply Last reply
          0
          • E ednrgc

            Normally, you would just make the property text, there's no reason to show the entire label.

            C Offline
            C Offline
            cheeken2u
            wrote on last edited by
            #5

            '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

            E 1 Reply Last reply
            0
            • C cheeken2u

              '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

              E Offline
              E Offline
              ednrgc
              wrote on last edited by
              #6

              It seems like you didn't place this into the user control. Then add an accessor in the page.

              C 1 Reply Last reply
              0
              • E ednrgc

                It seems like you didn't place this into the user control. Then add an accessor in the page.

                C Offline
                C Offline
                cheeken2u
                wrote on last edited by
                #7

                i am the beginner for asp.net, can you show me the code ? thanks.

                Best regards, Chee ken

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups