在asp.net中可以写一个通用的页面,即把所有的公共变量或函数写在这个页面中然后在所需要引用函数的页面中把此页包含进来就行我。
在C#中我是把公共变量或函数写在一个类中然后引入即可..

解决方案 »

  1.   

    怎么包含啊?
    我用的是codebihand技术,页面和C#脚本是分离的!
    怎么把公共页面包含进去?
      

  2.   

    我提供个思路:可以用C#脚本写一个类,这个类包含所有你想要的函数。索性就叫他pubFuncClass.然后在页面中引入。不知如何?
      

  3.   

    我想界面包函做成控件是最好的重用方法,对于公用函数放在类中在codebehind中引用即可。
      

  4.   

    做一个公共的类:
    public YourNameSpace{
        class Function{
            void static YourFunction1(...);
            bool static YourFunction2(...);
        }
    }调用的时候:
    using YourNameSpace;Function.YourFunction1(...);
    bool bRet = Function.YourFunction2(...);
      

  5.   

    这是我的错误信息:
    The type or namespace name 'test' could not be found (are you missing a using directive or an assembly reference?)Source Error: Line 22:  {
    Line 23:  // Put user code to initialize the page here
    Line 24:  string c=test.conn();
    Line 25:  }
    Line 26: 
     这是我的公共函数文件
    using System;namespace chen
    {
    /// <summary>
    /// Summary description for test.
    /// </summary>
    public class test
    {
    public test()
    {
    //
    // TODO: Add constructor logic here
    //
    //string te=conn();
    }
    public string conn()
    {
    string coon="sssss";
    return coon;
    }


    }
    }
    这是我调用的文件源码!using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using chen;namespace chen
    { /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    string c=conn();
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
    }
    }
      

  6.   

    试一试test newtest=new test();
      string c=newtest.conn();
      

  7.   

    在同一个namespace下就可以互调函数比如你在page1.aspx.cs下
    有个
    namespace website{
       public class Function1{
          public void function_a(){......}
          public void function_b(){......}
    }
    }
    那么在page2.aspx.cs下
    也这样写
    namespace website{
       public class test{
         Function1 func1=new Function1();
         func1.function_a();//这样就可以直接调用
    }
    }