DotNet2.0专题
关注DotNet,传播DotNet。

  在asp.net 2.0中,只需要在web.config里定义你要用的那些namespace,则在aspx页面中就不需要再象1.1那样,用
<%@ import namespace="system.text" %>来引用了。比如,只需要在web.config中,以这样的方式就可以了:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  
<system.web>
    
<pages>
      
<namespaces>
        
<add namespace ="System.IO" />
        
<add namespace="System.Text"/>
      
</namespaces>
    
</pages>
  
</configuration>
</system.web>

  这样一来,在所有的aspx页面中(注意不是codebehind页面),则不需要再用import的方法引入了。

  同样道理,在asp.net 1.1中,自定义控件的引用,在aspx页面中也是很麻烦的,在asp.net 2.0中,可以在web.config中这样定义:

<%@Register TagPrefix="uc" Namespace="xxxxxx" Assembly="xx" %>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  
<system.web>
    
<pages>
      
<namespaces>
        
<add namespace ="System.IO" />
        
<add namespace="System.Text"/>
      
</namespaces>
      
<controls>
        
<add tagPrefix="uc" namespace="xx" assembly="xxxx" /> 
      
</controls>
    
</pages>
  
</configuration>
</system.web>

  这样,在aspx页面中,只需要用uc来引用就可以了,十分方便。

posted on 2006-06-27 16:02  InitialC  阅读(597)  评论(1)    收藏  举报