All controls are null within usercontrol

后端 未结 4 2214
醉酒成梦
醉酒成梦 2021-02-18 13:27

I have a UserControl which uses a UserControl, among other controls.

In the ascx file I have the following code:

<%@ Register TagPrefix=         


        
4条回答
  •  死守一世寂寞
    2021-02-18 14:04

    If the user control is in your current project, then you need to include the src in the register statement:

    <%@ Register TagPrefix="uc1" TagName="NavTop" Src="controls/NavTop.ascx" %>
    

    However, if you use this user control in more than one page, then you can also register it in web.config:

    
      
        
          
        
      
    
    

    One other thing to be aware of: there are times when the visual studio designer does not "see" your changes to controls on the page if you only make the changes in source view. If you change a control name, for example, you could end up with a control with the new name in the ascx but a reference to a control with the old name in the designer file. At runtime, this will result in the designer file property being null.

    After having been burnt by this a number of times, if I make any changes in source view, I either check to see that the designer file has been updated correctly or I switch to design view, make a minor change, then save the page/user control.

提交回复
热议问题