如何在后面的每个代码中添加默认名称空间 [英] How to add default namespace in every code behind

查看:85
本文介绍了如何在后面的每个代码中添加默认名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在每个页面中添加system.web命名空间,因此我将其写入web.config中,如下所示:

I do not want to add system.web namespace in every page so i write it into the web.config like this:

<system.web>
  <pages>
    <namespaces>
      <clear/>
      <add namespace="System.Data" />
    </namespaces>
  </pages>
</system.web>




但这行不通.

在web.config中写入名称空间后,我需要在webform1.aspx.cs中写入System.Data.如果我没有在CS文件中写入System.Data,那么他会给出错误,即找不到数据集或其他类




But it could not work.

After writing namespace in the web.config I need to write System.Data in the webform1.aspx.cs,If i dont write that in cs file then he gives error that dataset or other classes not found

推荐答案

如果要在每个新的代码文件中添加此文本,请更改模板!
有一个技巧可以向您显示如何:添加项目到Visual Studio默认文件 [ ^ ]

这不会影响现有文件,但是向它们添加using行很简单-这是我所知道的唯一方法,因为编译器不会引用web.config(它不会)不知道它在哪里-可能正在为台式机或Web编译.)
If you want to add this text in every new code file, then change the template!
There is a Tip which will show you how here: Adding your items to Visual Studio default files[^]

This won''t affect existing files, but it is a simple matter to add the using line to them - that is the only way I know of to do this as the compiler does not reference web.config (it doesn''t know where it is - it could be compiling for desktop or web).


这篇关于如何在后面的每个代码中添加默认名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆