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. General Programming
  3. C#
  4. Referencing object by substituing object name in c#?

Referencing object by substituing object name in c#?

Scheduled Pinned Locked Moved C#
csharpdesigntutorialquestion
2 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.
  • D Offline
    D Offline
    dug_r
    wrote on last edited by
    #1

    Is there a way in c# to create a string and use that as an object or control name? For example, if I had an object "listBox.foo", and 2 string variables "string string1 = "listBox"; string string2 = "foo";, is there anyway to build the object name from that so I could call a method like ${string1+"."+string2"}.Visible=false" Thanks for any pointers! I have looked at the FindControl function so I could do "mycontrol = FindControl(string1+string2); mycontrol.Visible=false". However, although I use System.Web.UI, the compiler still complains that it's not available in the context.

    D 1 Reply Last reply
    0
    • D dug_r

      Is there a way in c# to create a string and use that as an object or control name? For example, if I had an object "listBox.foo", and 2 string variables "string string1 = "listBox"; string string2 = "foo";, is there anyway to build the object name from that so I could call a method like ${string1+"."+string2"}.Visible=false" Thanks for any pointers! I have looked at the FindControl function so I could do "mycontrol = FindControl(string1+string2); mycontrol.Visible=false". However, although I use System.Web.UI, the compiler still complains that it's not available in the context.

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Like this: string x = "control_name"; this.Controls[x].Visible = false;

      जय हिंद

      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