2017-05-29 83 views
0

我有一个使用asp.net构建的网站。无法投入'ASP.MyControlName_ascx'类型的对象来键入'MyControlName'

在我的本地电脑这工作正常。但我这个部署在服务器上后,我得到了以下错误味精当我尝试去到一个页面

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

加载ASCX文件我用这个代码

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

的哪些错误?

+1

您在使用'Page.LoadControl'加载'skillbind' ASCX控制?显示更多详细信息,包括代码背后的ASCX和ASPX页面标记。 –

+0

@TetsuyaYamamoto嗨朋友更新了这个问题 –

回答

0

问题似乎添加用户控件到页面之前,源于ID属性的分配:

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

回到与web表单过去的时候,我发现用户控制前应加Control继承容器分配给它的任何属性,通过交换二,三线,使用户控制,即工作:

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页面(或多个)该基准指令行持SkillBind控制:

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

然后添加在web.config中的开发版本这个元素来冲洗掉这样的错误(可选):

<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'.

相关问题