Search code examples
asp.netvb.netfindcontrol

FindControl in Asp.Net


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.


Solution

  • 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.