ASP.Net-从外部CS源文件内部调用函数 [英] ASP.Net - Call a function from inside an external cs source file
问题描述
我在asp.net/c#中似乎很容易的任务苦苦挣扎了比我想要的更长的时间.我认为这很容易,因为我了解C/C ++,JavaScript,VBScript和VB.Net的语法.
我有一个aspx页面,我想包含一个c#源文件,该文件定义并调用使用HTTP响应的函数.我不希望在aspx页面上有任何此代码,因为在Notepad ++的aspx页面上没有嵌入c#的语法颜色.
任何帮助,将不胜感激.这是一些伪代码,可帮助您了解我要在哪里结束:
test.aspx
I''ve been struggling with what seemed like an easy task in asp.net/c# for longer than I would like. I thought this would be easy, since I understand the syntax of C/C++, JavaScript, VBScript, and VB.Net.
I have an aspx page and I would like to include a c# source file that defines and calls a function that uses HTTP Response. I do not want to have any of this code on the aspx page because there is no syntax coloring for c# embedded on an aspx page in Notepad++.
Any help would be appreciated. Here''s some pseudo code to help you understand where I''m trying to end up:
test.aspx
<%@ Page language="c#" Src="test.cs" %>
test.cs
test.cs
//Import
using System.Web.HttpContext.Current.Response;
//Define
public class myclass()
{
public void myfunction()
{
Response.Write("Hello World");
}
}
//Call
myclass::myfunction();
另外,您是否已经在访问类的成员之前从类中创建了一个对象? C ++允许通过::运算符直接访问类的函数.
Also, do you -have- create an object from a class before accessing the members of it? C++ allows direct access to a classes'' functions via the :: operator.
推荐答案
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
您的csharp代码将为:
Your csharp code will be:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
请记住,.NET使用OOP范式=)
可能对您有帮助: http://www.asp.net/web-pages [
Remember that .NET uses OOP paradigm =)
May be this helps you: http://www.asp.net/web-pages[^]
Hope you find it useful.
这篇关于ASP.Net-从外部CS源文件内部调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!