FindControl in Asp.Net

selvaraj picture selvaraj · Jan 7, 2011 · Viewed 16.4k times · Source

I'm trying to find a control in a page. The Id is available as a server control (CheckBox) This throws exception "not able to convert string to double"

Dim taskId As HtmlInputCheckBox
i =10
taskId = Me.FindControl("chkTaskOption_" + i)
taskId.Checked = True

Can any one tell me where i'm wrong.

Answer

patmortech picture patmortech · Jan 7, 2011

Your problem is that you need to use & instead of + to concatenate two strings in VB.NET. Change this line:

taskId = Me.FindControl("chkTaskOption_" & i)

For further reading, there's a good discussion about this in the answers to this question.