943,922 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1868
  • ASP.NET RSS
Sep 18th, 2009
0

convert string to object type

Expand Post »
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.
ASP.NET Syntax (Toggle Plain Text)
  1. 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
Similar Threads
Reputation Points: 22
Solved Threads: 9
Junior Poster
ninjaimp is offline Offline
129 posts
since Apr 2008
Sep 21st, 2009
0

Re: convert string to object type

Use a condition before casting the control like this:

ASP.NET Syntax (Toggle Plain Text)
  1. If TypeOf(Me.Page.FindControl(control1)) IS DropDownList Then
  2. CType(Me.Page.FindControl(control1), DropDownList).SelectedIndex = xyz
  3. End If

regards,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Datsun90 is offline Offline
22 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: ASP.Net timer control
Next Thread in ASP.NET Forum Timeline: need some information regarding ASP.Net Project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC