Poser une questionPoser une question
 

QuestionWebpart and Loadcontrol

  • mercredi 9 juillet 2008 07:03Q-P Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du code
    Hi,

    I am creating webparts (ASP.NET 2.0) for Sharepoint and want to separate the UI code from the actual webpart code. I am trying to do this by placing the UI code in an ascx-file that I copy to "TEMPLATE\USERCONTROLS". That code should then be loaded in to the webpart with Page.LoadControl.

    For test purposes I have loaded the Welcome.ascx (Sharepoint login menu) into my webpart  (this.Controls.Add(Page.LoadControl(@"~/_controltemplates/Welcome.ascx")) in CreateChildControls) and it works well. However, when I try to load my custom controls, I get the message (from try/catch) "The file '/_controltemplates/<filename>' does not exist."

    For example, I copied the Welcome.ascx to WelcomeCopy.ascx but still after "this.Controls.Add(Page.LoadControl(@"~/_controltemplates/WelcomeCopy.ascx"));" I get the message "The file '/_controltemplates/WelcomeCopy.ascx' does not exist." What am I doing wrong? The files both have the same permissions and no error is shown in the applications page of event viewer.

    To make this even more confusing, the custom control seems to sometimes load and the next refresh I get the file does not exist error message again.

Toutes les réponses