Error loading control and accessing its methods

Aug 26, 2008 at 5:33 PM
Hi all,

My team and I have developed a sharepoint application using smartpart and usercontrols. The problem is that I would like to load and navigate through those controls from other web part by calling a control class method. As shown below:

override void CreateChildControls()
    UserControl uc = (UserControl)this.Page.LoadControl("~/usercontrols/ProgramasSociaisView.ascx");
    HiddenField txtPSEUO = (HiddenField)uc.FindControl("txtCD_PSEUO");
    txtPSEUO.Value =
ProgramasSociaisView)uc).viewProgram();     <== Unable to cast object of type 'ASP.usercontrols_programassociaisview_ascx' to type 'Webparts.UI.ProgramasSociaisView'.

Can anyone give me a clue on that? I know I can't cast that object. Is there any other way to call that control class (*.ascx.cs) method?

Thanks in advance for any help.