在asp.net中可以写一个通用的页面,即把所有的公共变量或函数写在这个页面中然后在所需要引用函数的页面中把此页包含进来就行我。
在C#中我是把公共变量或函数写在一个类中然后引入即可..
在C#中我是把公共变量或函数写在一个类中然后引入即可..
解决方案 »
- 有用Coolite做项目的吗 问个GridPanel刷新的问题
- 请教各位大侠一个关于IIS执行.exe文件的问题
- 如何让表格中内容居中?
- 数据库用0和1表示是和否.怎么用数据绑定控件显示是和否
- 动态生成文本框,然后怎么获得值啊?希望各位高手帮帮忙.谢谢!
- div跟dropdownlist不在同一页面上怎么解决dropdownlist总是在最前面显示的问题
- 如何把iframe页里的变量传到父页的web控件中?
- .net能不能在XP professional下正常使用?急,在线等!
- 设置主页的问题
- 关于连接oracle数据问题.
- 我想编写一自定义Web控件,需要点击TextBox时...
- 欢迎大家光临C#资源网---csource.yeah.net
我用的是codebihand技术,页面和C#脚本是分离的!
怎么把公共页面包含进去?
public YourNameSpace{
class Function{
void static YourFunction1(...);
bool static YourFunction2(...);
}
}调用的时候:
using YourNameSpace;Function.YourFunction1(...);
bool bRet = Function.YourFunction2(...);
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
}
}
string c=newtest.conn();
有个
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();//这样就可以直接调用
}
}