2017-05-29 3 views
0

Ich habe eine Website, die mithilfe von asp.net erstellt wird.Kann Objekt des Typs 'ASP.MyControlName_ascx' nicht umwandeln, um 'MyControlName' einzugeben

In meinem lokalen PC funktioniert das gut. Aber nachdem ich diese auf dem Server bereitstellen hätte folgend ich Fehler msg, wenn ich auf eine Seite zu gehen versuchen

--Data--System.Collections.ListDictionaryInternal--Base Exception--System.InvalidCastException: Unable to cast object of type 'ASP.uc_eventmanagment_skill_skillbind_ascx' to type 'HRMS.uc.Skill.SkillBind'. 
    at HRMS.Task.LoadAdminPanels(String page) 
    at HRMS.Task.Page_Load(Object sender, EventArgs e) 
    at System.Web.UI.Control.OnLoad(EventArgs e) 
    at System.Web.UI.Control.LoadRecursive() 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)--Inner Exception--System.InvalidCastException: Unable to cast object of type 'ASP.uc_eventmanagment_skill_skillbind_ascx' to type 'HRMS.uc.Skill.SkillBind'. 
    at HRMS.Task.LoadAdminPanels(String page) 
    at HRMS.Task.Page_Load(Object sender, EventArgs e) 
    at System.Web.UI.Control.OnLoad(EventArgs e) 
    at System.Web.UI.Control.LoadRecursive() 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)--Source--System.Web--StackTrace-- at System.Web.UI.Page.HandleError(Exception e) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest() 
    at System.Web.UI.Page.ProcessRequest(HttpContext context) 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

auf die ASCX-Datei zu laden ich diesen Code verwenden

  SkillBind SkillBind = (SkillBind)LoadControl("/uc/EventManagment/Skill/SkillBind.ascx"); 
      SkillBind.ID = "SkillBind"; 
      pHolderContainer.Controls.Add(SkillBind); 

Was ist falsch?

+1

Haben Sie 'Page.LoadControl' mit' skillbind' ASCX Steuerung zu laden? Weitere Details anzeigen, einschließlich ASCX & ASPX-Seitenmarkierungen mit Code dahinter. –

+0

@TetsuyaYamamoto Hallo Freund aktualisiert die Frage –

Antwort

0

Das Problem von Zuordnung von ID Attribut stammen scheint, bevor Benutzersteuerung auf die Seite hinzufügen:

SkillBind.ID = "SkillBind"; 
pHolderContainer.Controls.Add(SkillBind); 

Zurück zu den vergangenen Zeiten mit Webforms, fand ich, dass der Benutzer die Kontrolle sollte vor dem Control geerbt Behälter hinzugefügt werden jedes Attribut, um es, dh durch Vertauschen zweite und dritte Zeile Zuweisung von Benutzersteuerung machen gearbeitet:

SkillBind SkillBind = (SkillBind)LoadControl("/uc/EventManagment/Skill/SkillBind.ascx"); 
pHolderContainer.Controls.Add(SkillBind); // assign user control first 
SkillBind.ID = "SkillBind"; // then setting ID attribute 

vergessen sie auch nicht auf ASPX Seite dieser Referenzrichtlinie Linie enthalten (s)

<%@ Reference Control="/uc/EventManagment/Skill/SkillBind.ascx" %> 

Dann fügen Sie dieses Element in Entwicklungsversion von web.config solche Fehler zu spülen (optional): SkillBind Kontrolle halten

<compilation batch="false"/> 

Danach versuchen & das Projekt neu aufzuräumen.

Verwandte Themen:

Unable to cast object of type 'X' to type 'X' - ASP.NET

Unable to cast object of type 'ASP.MyControlName_ascx' to type 'MyControlName'.

Verwandte Themen