Hi

I have a procedure that performs checks on controls in my page against rules set in a SQL table. It all works fine except that when im casting the control e.g.

CType(Me.Page.FindControl(control1), TextBox).Text

and its a dropdownlist it of course fails.

Im trying to create a variable that gets populated from the table with the correct control type and then use this in the cast. i.e replace textbvox with my variable that could say either 'textbox' or 'dropdownlist'

but if i just put the string value variable in it gives error 'Type 'ControlType' is not defined'.

I wonderd if anyonme had any ideas

Use a condition before casting the control like this:

If TypeOf(Me.Page.FindControl(control1)) IS DropDownList Then
    CType(Me.Page.FindControl(control1), DropDownList).SelectedIndex = xyz
End If

regards,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.