ASP.NET 2.5 prefixing ctl00 and ASP.NET 4 not prefixing ctl00

后端 未结 4 422
后悔当初
后悔当初 2020-11-30 11:23

Does anyone know why ASP.NET 4 has dropped the ctl00 prefix on ASP controls?

Is there a setting I have missed?

4条回答
  •  温柔的废话
    2020-11-30 11:59

    As far as i remember its up to ASP.NET to decide which prefix to use. Its a bad practice to reference on the controls with hardcoded id value.

    You should use ClientId property that will always generate you proper Id:

    
        
    
    
         

    In the example above, its calculating proper ID of the textbox and putting it into label attribute. In this way you will no more worry about keeping the same id of the control.

提交回复
热议问题