Referencing object by substituing object name in c#?
-
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.
-
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.