如何再asp.net中定义一个全局得类,再各个页面都可以实例化,比如说数据库连接类!并且再类创建好以后,如何再各个页面实例化刚创建得类!

解决方案 »

  1.   

    直接在你的项目里面添加一个类,就是全局可以用的使用的时候
    yourClass yc = new yourClass()
      

  2.   

    public class Common
    {
      public static xxxClass xc = new xxxClass();
    }在其他类使用
    Common.xxxClass.xxMethod();
      

  3.   

    这样的工具类
    还是用static method好
      

  4.   

    我得意思是在一个asp.net工程中所有文件!都使用同一个类,那么这个类在什么地方定义,在其他所有得文件中怎么调用!
      

  5.   

    这个类在什么地方定义没有任何关系
    随便你什么地方定义你还是用静态类吧
    class xx
    {
        public void statci xxxx()
        {
        }
    }在任何地方调用都是xx.xxxx()
      

  6.   

    在Web.config填加节
    <appSettings>
     <add key="SqlServerConnectionString" value="server=(local);user id=;pwd=;database=></add>
    </appSettings>写一个Common类,里面定义变量如下public Class Common
    {
      public String ConnectionString
      {
        return connection_string;
      }  Private String connection_string = System.Config.Configuration.AppSetting["SqlServerConnectionString"];}
      

  7.   

    建议楼主用Microsoft Data Access Application Block:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp----------------------------------------
    欢迎使用AspNetPager免费分页控件:http://www.webdiyer.com
      

  8.   

    bin里定义连接后
    页面调用
    dim db as new bin名称空间.名称类
    db.conn就 OK了
      

  9.   

    建一个类,名字空间为:Test.DBConn
    class C_DBConn
    {
        //
        private string strConn;    pulbic C_DBConn
        {    }
        
        //
        public string GetConn(string conn)
        {
        //your code,get conn
        return strConn;
        }}
    用的时候:
    using System;
    using Test.DBConn;namespace Test.Test
    {
        class Test1
        {
            private string strConn;
            public Test1()
            {}        public GetConn()
            {
                C_DBConn myConn = new C_DBConn();
                this.strConn = myConn.GetConn(strConn);
            }
        }
    }
    这只是一个例子,用的时候不这样用。