简体   繁体   中英

aspx c# code behind not recognizing controls

I created a child template from visual studio to manage my kentico template. The template worked fine except that all the controls in it is not accessible from code behind because it is not recognized. I have checked for on line solution but none solved the issue. I even got this link Codebehind file doesn't recognize aspx-controls without any luck since I can't even access the myfile.aspx.designer.cs.

What do I trie again?

Note: My controls are not inside any panel or other control. Just inside a normal div.

Try adding runat="server" to your id tag.

Here is an example.

<tr class="headerrow" id="tbrHeader" runat="server">  

I am unfamiliar with Kentico, but this is what I have come up with as possible solutions without having seen your code:

  • Make sure all your controls have a 'runat' attribute: runat="server" . I am not trying to insult your intelligence, but it is an easy thing to forget(As I have done before), without this the control won't be recognised from code-behind

  • If it is a template file, have you made sure the codebehind that refers to it, is the code-behind of the template file, as the codebehind of other pages will not be able to find the control in the template without you telling them where it is.

  • With your new comment on the question: If your class is abstract, have you tried wrapping it in a non-abstract class? (source: stackoverflow.com/questions/481305)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM