This is a migrated thread and some comments may be shown as answers.

Unable to cast object of type 'Telerik.Web.UI.RadMultiPage' to type 'System.Web.UI.UserControl'.

1 Answer 138 Views
Documentation and Tutorials
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 2
Doug asked on 10 Jan 2012, 02:39 PM
error: Unable to cast object of type 'Telerik.Web.UI.RadMultiPage' to type 'System.Web.UI.UserControl'.

When going through a user control for a EditFormUserControl and I wanted to list all the user controls on that page but doing a foreach loop I need a fairly consistent type to iterate through.  So how can I iterate through 'userControl' when it could be a lteral for a label or  a 'RadMultiPage' or a 'UserControl'.  I have tried ...string objectTypeName="RadMultiPage";

 

Type

 

T = Type

 

.GetType(objectTypeName);

 

((

typeof(T)))userControl).Controls

 

 

But I just wanter to be able to have a reursive call listing out all the children be them Usercontrol or Telerik User controls. 
Any Ideas ?
Doug

 

 

 

UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

foreach

 

(object uc in ((UserControl)userControl).Controls){}

 

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 13 Jan 2012, 02:41 PM
Hi Doug,

Please refer to the following forum post that might give you a clearer understanding of how you can achieve the desired behavior:

  • http://forums.asp.net/t/1726687.aspx/1
  • http://stackoverflow.com/questions/3834544/loop-through-controls-of-a-usercontrol
  • http://stackoverflow.com/questions/2632302/loop-through-all-the-user-controls-on-a-page
  • http://aspmessageboard.com/showthread.php?t=161740

Kind regards,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Documentation and Tutorials
Asked by
Doug
Top achievements
Rank 2
Answers by
Kate
Telerik team
Share this question
or