Help casting a dynamic user control to the type i need

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi all, I am adding dynamic user controls with the simple code as follows:

MyPlaceHolder.Controls.Add(LoadControl("MyUserControl.ascx"));

I then want to run a member on my user control, something like:

MyPlaceHolder.Controls[i].TheMemberFunction();

However I cannot do this as it obviously has not cast the User Control to
its own type and therefore cannot reference the member function.

How can i cast my User Control into the "MyUserControl" before adding it
into the controls array for the place holder (or after for that matter?).
Any attemps sees error along the lines of "A control cannot be case to
UserControl".

Thank you for any help.
Kind Regards
Tarun


.



Relevant Pages

  • Simple user control with a single ReadOnly Property. "NOT A MEMBER OF" ??
    ... Simple user control with a single ReadOnly Property. ... My control will be called DateDropDown. ... not a member of DateDropDown ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: is not accessible in this context because it is Protected
    ... Protected means that only the class in which the member is defined ... > Simply I have a user control that contains form controls and I would like ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Finding a dynamically added control - Quite Urgent :-(
    ... would be the user control e.g run FindControl against the user control. ... Another way could be exposing the TextBox outside the user control as an ... it and then create a property which accesses this member). ... > txtUsername = new TextBox; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Custom server control running code before page_load?
    ... You'll have to access HttpContext.Current.Handler and cast it to a Page. ... Therefor thought I'd do a @Register in the Page for an user control which runs in Pre-Render event and does this. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Casting to parent page from user control - how??
    ... problem with this is that it ties your user control to that particular page - which defeats part of the purpose of using a user control... ... There's a user control on page and I want to meka a cast like this ... I can't even put any base classes to that crazy App_Code folder ... How to get rid of this terrible App_code folder and make things work? ...
    (microsoft.public.dotnet.framework.aspnet)