Asp.net controls are not accessible in code behind

后端 未结 26 1202
慢半拍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:01

    This happens especially with older stuff in visual studio.

    In 1.1 (before "partial classes") you could always see the control declarations in the code-behind.

    In later versions, they moved that into a cs.designer file (so now you've got partial classes -- part in the .cs.designer file, and part in the .cs file).

    If you're working with a visual studio "project", then you can open the cs.designer file, and add your control. Just look at how all of the other controls are declared -- that's all you have to do.

    If you're working with a visual studio "website", then you're out of luck. There's no way to view or edit the cs.designer file, because it isn't there until the website is compiled.

提交回复
热议问题