Asp.net controls are not accessible in code behind

后端 未结 26 1175
慢半拍i
慢半拍i 2020-12-15 16:25

I have a project that was previously built by someone else. When I try to add a new control to the page, I can\'t access it in the code behind. When I try to access it there

26条回答
  •  遥遥无期
    2020-12-15 17:13

    I had a similar problem. I faced this problem when I tried to rename the aspx file. In my case, the class name was not updated from UpdateRecords to ModifyRecords when I renamed the aspx file to ModifyRecords. Hence none of the ASP.NET controls were accessible from the code behind.

    Code behind before renaming:

    public partial class UpdateRecords : System.Web.UI.Page
    

    Code behind after renaming:

    public partial class ModifyRecords : System.Web.UI.Page
    

    If you try to rename aspx file or copy-paste from different file, just make sure, the class name is updated.

提交回复
热议问题