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:

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

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.