在一个.cs中如何调用其他.cs

new36198 2007-04-16 12:23:25
我的a.aspx.cs如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using Searth;

public partial class web_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
......................
}
}

我新建了一个类Searth.cs如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Searth 的摘要说明
/// </summary>
public class Searth
{
public Searth()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}


那我在这个a.aspx.cs中如何才能调用到Searth.cs?

备注:这两个文件我都是放同一个目录下的,并没有放在App_Code中
...全文
432 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
windstore 2007-04-16
  • 打赏
  • 举报
回复
namesapce search
{
public class Searth
{
public Searth()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
}



那个aspx页面。。。 using search;就可以了。。。 或者将CS放到App_Code中,直接可以用了
wangchao1982 2007-04-16
  • 打赏
  • 举报
回复
你这里也没有命名空间,也不在同一个工程项目中.跟你一起期待答案
new36198 2007-04-16
  • 打赏
  • 举报
回复
a里面将Searth实例化是什么意思?
new36198 2007-04-16
  • 打赏
  • 举报
回复
我这里有很多页面都有搜索框,我想把搜索集中到一个页面执行
本来是想每个页面(例如:a.aspx.cs)中分别写的(然后在Redirect一下到SearthPro.aspx),但这样好麻烦,所以想做个公用的类,然后一起使用
江城老温 2007-04-16
  • 打赏
  • 举报
回复
在a里面将Searth实例化就可以用了啊。 //PS:Searth是什么?
sqfeiyu 2007-04-16
  • 打赏
  • 举报
回复
不知你說的調用是調用什么﹐如果是函數或方法的話﹐除非是靜態﹐否則是不行的。
如果是變量的話﹐就是頁面之間的傳值了﹐放在Session中傳遞就可以了
huainian123 2007-04-16
  • 打赏
  • 举报
回复
前面加上using 命名空间,后面要用的时候new一下。
xiaoliangwh 2007-04-16
  • 打赏
  • 举报
回复
帮顶 !
xioxu 2007-04-16
  • 打赏
  • 举报
回复
上边说的很清楚了,注意命名空间。实例化就是new 后
gui0605 2007-04-16
  • 打赏
  • 举报
回复
最基础的东西
YunAo2008 2007-04-16
  • 打赏
  • 举报
回复
a里面将Searth实例化是什么意思?
new36198 2007-04-16
  • 打赏
  • 举报
回复
我现在这样写好象可以引用,但不知道如何处理?
protected void Button1_Click(object sender, EventArgs e)
{
string SearthName = Request["SearthName"];
if (RadioButton1.Checked)
{
Searth.Send(this, "1",SearthName);//1表示博客搜索
Response.End();
}
if (RadioButton2.Checked)
{
Searth.Send(this, "2", SearthName);//2表示论坛搜索
Response.End();
}

}


下面是被引用的这个类:
public class Searth
{
public static void Send(System.Web.UI.Page page, string Pro, string Searth)
{
//我想在这里打开新窗口,例如打开:Searth.aspx?Type=1&SearthName=Searth
}
}
new36198 2007-04-16
  • 打赏
  • 举报
回复
能具体点吗?我网上看了写资料,说要先把searth.cs编译成dll还有就是一个实例化,但不是很清楚,请各位帮帮忙
balenoww 2007-04-16
  • 打赏
  • 举报
回复
在你的 searchcs页面加个namespace search
new36198 2007-04-16
  • 打赏
  • 举报
回复
我用
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Searth;

提示:
编译器错误信息: CS0246: 找不到类型或命名空间名称“Searth”(是否缺少 using 指令或程序集引用?)
Jock.Chen 2007-04-16
  • 打赏
  • 举报
回复
public class Searth
{
private static Searth searth;
private Searth()
{
}

public static Searth Instance()
{
if(searth == null)
{
searth = new Searth();
}
return searth;
}

public void Response(Page page,string Msg)
{
page.Response.Write(string.Format("<script>alert('{0}');</script>",Msg));
}
}

//a中调用
private void Button3_Click(object sender, System.EventArgs e)
{
Searth.Instance().Response(this,"Message");
}
类很多,不写全了。。下载下来好好看 ----------Database-------------- 1.DataTable帮助类(DataTableHelper.cs) 2.Access数据库文件操作辅助类(JetAccessUtil.cs) 5.查询条件组合辅助类(SearchCondition.cs) 6.查询信息实体类(SearchInfo.cs) 8.Sql命令操作函数(可用于安装程序的时候数据库脚本执行)(SqlScriptHelper.cs) ----------Device-------------- 声音播放辅助类(AudioHelper.cs) 摄像头操作辅助类,包括开启、关闭、抓图、设置等功能(Camera.cs) 提供用于操作【剪切板】的方法(ClipboardHelper.cs) 获取电脑信息(Computer.cs) 提供用户硬件唯一信息的辅助类(FingerprintHelper.cs) 读取指定盘符的硬盘序列号(HardwareInfoHelper.cs) 提供访问键盘当前状态的属性(KeyboardHelper.cs) 全局键盘钩子。这可以用来在全球范围内捕捉键盘输入。(KeyboardHook.cs) 模拟鼠标点击(MouseHelper.cs) 全局鼠标钩子。这可以用来在全球范围内捕获鼠标输入。(MouseHook.cs) MP3文件播放操作辅助类(MP3Helper.cs) 关联文件(ExtensionAttachUtil.cs) 注册文件关联的辅助类(FileAssociationsHelper.cs) 打开、保存文件对话框操作辅助类(FileDialogHelper.cs) 常用的文件操作辅助类FileUtil(FileUtil.cs) INI文件操作辅助类(INIFileUtil.cs) 独立存储操作辅助类(IsolatedStorageHelper.cs) 序列号操作辅助类(Serializer.cs) 获取一个对象,它提供用于访问经常引用的目录的属性。(SpecialDirectories.cs) 简单的Word操作对象(WordCombineUtil.cs) 这个类提供了一些实用的方法来转换XML和对象。(XmlConvertor.cs) XML操作类(XmlHelper.cs) ----------Format-------------- 参数验证的通用验证程序。(ArgumentValidation.cs) 这个类提供了实用方法的字节数组和图像之间的转换。(ByteImageConvertor.cs) byte字节数组操作辅助类(BytesTools.cs) 处理数据类型转换,数制转换、编码转换相关的类(ConvertHelper.cs) CRC校验辅助类(CRCUtils.cs) 枚举操作公共类(EnumHelper.cs) 身份证操作辅助类(IDCardHelper.cs) 检测字符编码的类(IdentifyEncoding.cs) RGB颜色操作辅助类(MyColors.cs) 日期操作类(MyDateTime.cs) 转换人民币大小金额辅助类(RMBUtil.cs) 常用的字符串常量(StringConstants.cs) 简要说明TextHelper。(StringUtil.cs) 获取文字首字拼写,随机发生器,按指定概率随机执行操作(Util.cs) 各种输入格式验证辅助类(ValidateUtil.cs) ----------Network-------------- Cookie操作辅助类(CookieManger.cs) FTP操作辅助类(FTPHelper.cs) HTML操作类(HttpHelper.cs) 网页抓取帮助(HttpWebRequestHelper.cs) Net(NetworkUtil.cs) IE代理设置辅助类(ProxyHelper.cs) ----------Winform-------------- 跨线程的控件安全访问方式(CallCtrlWithThreadSafety.cs) CheckBoxList(CheckBoxListUtil.cs) 窗口管理类(ChildWinManagement.cs) 由马丁·米勒http://msdn.microsoft.com/en-us/library/ms996492.aspx提供一个简单的方法打印工作的一个RichTextBox一个帮手(ExRichTextBoxPrintHelper.cs) 显示,隐藏或关闭动画形式。(FormAnimator.cs) 对窗体进行冻结、解冻操作辅助类(FreezeWindowUtil.cs) 窗体全屏操作辅助类(FullScreenHelper.cs) GDI操作辅助类(GDI.cs) 提供静态方法来读取这两个文件夹和文件的系统图标。(IconReaderHelper.cs) 图片对象比较、缩放、缩略图、水印、压缩、转换、编码等操作辅助类(ImageHelper.cs) 输入法帮助,全角 转换为半角(ImeHelper.cs) Winform提示框 的摘要说明。(MessageUtil.cs) 包含互操作方法调用的应用程序使用。(NativeMethods.cs) 托盘图标辅助类(NotifyIconHelper.cs) 打印机类(POSPrinter.cs) 图片、光标、图标、位图等资源操作辅助类(ResourceHelper.cs) RTF字符格式辅助类(RTFUtility.cs) 串口开发辅助类(SerialPortUtil.cs) 设置文本属性提供一个ToolStripStatusLabel(SafeToolStripLabel.cs) 只运行一个实例及系统自动启动辅助类(StartupHelper.cs) Web页面预览效果图片抓取辅助类(WebPageCapture.cs) 供Asp.Net直接调用的包装类(WebPreview.cs) 计算机重启、关电源、注销、关闭显示器辅助类(WindowsExitHelper.cs) 简单写了点,还有很多,希望能对大家有帮助 ================================================================================================ 本资料共包含以下附件: WHC.OrderWater.Commons.rar 公共类文档.docx

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧