2017-05-29 4 views
0

asp.netを使用して作成したWebサイトがあります。'ASP.MyControlName_ascx'タイプのオブジェクトを 'MyControlName'にキャストできません

私のローカルPCでこれは正常に動作します。私は、サーバー上でこれを展開した後、私はこのコード

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

いただきまし間違っを使用していますASCXファイルをロードするためのページ

--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) 

に行くしようとすると、しかし、私はエラーMSGを次しまいましたか?

+1

あなたは 'skillbind' ASCXコントロールをロードするために、' Page.LoadControl'を使用していますか? ASCXとASPXのページマークアップも含め、コードの背後にある詳細を表示してください。 –

+0

@TetsuyaYamamotoこんにちは友人が質問を更新しました –

答えて

0

問題がページにユーザーコントロールを追加する前にID属性の割り当てに由来ようだ:

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

戻る過去にWebフォームで、私は、ユーザーコントロールは前Control継承されたコンテナに追加されなければならないことがわかりましたそれに任意の属性を割り当て、ユーザーコントロールを作成するために、第2と第三のラインを交換することにより、IEが働いた:

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

また、ASPXページ(複数可)にこの参照指示行を含めることを忘れないでください

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

は、次に(オプション)このようなエラーを洗い流すためにweb.configファイルの開発バージョンでは、この要素を追加します:SkillBind制御保持その後

<compilation batch="false"/> 

を、プロジェクトを再構築&をクリーンアップしてみてください。

関連問題:

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

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

関連する問題