How do I evaluate a string that represents and object name as the object. I Know how to do this in a couple languages but not ASP.Net/VB.net I have 18 user controls on a page the controls are called Time1, Time2, Time3 etc... When the page loads I want to be able to set properties of them dynamically using a loop. This code is wrong but this is the jist of what I want. I cant find an eval or evaluate function. Basically want it to evaluate the string to the control like Time1.Hour = Request("Time1Hour") Dim i As Integer For i = 1 To 18 If Request("Time" & i & "Hour") <> Nothing Then eval("Time" & i & ".hour") = Request("Time" & i & "Hour") End If Next Any Idea? Is there another way to reference the controls on the page? This is the first time I have used custom server controls and I don't want to use the viewstate postback crap.
Ok..was being lazy before but found what I needed to get the control by a string that represented the controlid...if anyone is interested... me.FindControl(id as string) Dim i As Integer Dim T As TimeSelector For i = 1 To 18 If Request("Time" & i & "Hour") <> Nothing Then T = Me.FindControl("Time" & i) T.Hour = Request("Time" & i & "Hour") End If Next
you should really be doing enumuration of the controls on the page dim ctrl as Control For Each ctrl in Page.Controls if ctrl.GetType() == typeof(Timer) then 'do something end next look at how to do a for each statement in vb.net and the collection of the controls is in Page.Controls
Cool...yeah that is more generic....I guess I will start to delve into the UI stuff more in .Net. Up to this point most of the stuff I have done is back-end and when doing front end just using traditional methods (no controls, using url variables, regular form posts)