包含文件 [英] Include file

查看:41
本文介绍了包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是.NET世界的新手,很抱歉,如果这是一个常见问题。在经典的ASP中我经常使用带有一些标准函数的包含文件,例如。格式化一个

字符串。怎么做这个我.NET?


在我下面的测试代码中,我提交一个带有文本框的表单,使用

函数" format_string" ;改变价值。我也想在其他脚本中使用这个

函数,所以需要将代码放在另一个

文件中,并包含它,如何?


如果有人可以更改我的测试代码,我会很感激,以正确的方式向我展示




Thx ..


test.aspx

------------------

<%@ page language =" vb"继承= QUOT;试验" SRC =" test.vb" %>

< html>

< head>

< / head>


< body>

< form id =" test"方法= QUOT;交" runat =" server">

< asp:textbox id =" sometext"文本= QUOT;" RUNAT = QUOT;服务器" />

< asp:button id =" submit"文本= [提交" onclick =" test_me"

runat =" server" />

< / form>

< / body>

< / html>

------------------

test.vb

------------- -----

进口系统

进口System.Web.UI

公共类测试:继承页面

sub test_me(ByVal Sender As Object,ByVal E As EventArgs)

dim sometext as string

sometext = format_string(Request.Form(" sometext" ))

end sub


函数format_string(值为字符串)as string

return"!" &安培;价值与价值"!"

结束功能

结束班

----------------- -

I''m new in the .NET world, so sorry if this is a faq. In classic ASP I
often use a include file with some standard functions, ex. formating a
string an so. How do a do this i .NET ??

In my test code below, I submit a form with a textbox, use the
function "format_string" to change the value. I would like to use this
function in other scripts also, so need to place the code in another
file, and include it, how ?

I''ll appreciate if someone could change my test code, to show me the
right way to do it.

Thx..

test.aspx
------------------
<%@ page language="vb" inherits="test" src="test.vb" %>
<html>
<head>
</head>

<body>
<form id="test" method="post" runat="server">
<asp:textbox id="sometext" text="" runat="server" />
<asp:button id="submit" text="submit" onclick="test_me"
runat="server" />
</form>
</body>
</html>
------------------
test.vb
------------------
Imports System
Imports System.Web.UI

public class test : inherits page
sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
dim sometext as string
sometext = format_string(Request.Form("sometext"))
end sub

function format_string(value as string) as string
return "!" & value & "!"
end function
end class
------------------

推荐答案

您好


查看以下文章,其中讲述了如何

将文件包含在aspx中。

http://www.csharpfriends.com/Articles/getArticle.aspx?

articleID = 9

http://www.aspalliance.com/stevesmit...es/includelets

..asp


Ravikanth

Hi

Check out the following articles, which tells about How
to include files in aspx.

http://www.csharpfriends.com/Articles/getArticle.aspx?
articleID=9

http://www.aspalliance.com/stevesmit...es/includelets
..asp

Ravikanth

-----原始消息-----
我是.NET世界的新手,很抱歉,如果这是一个常见问题。在
中,经典ASP Ioften使用包含一些标准函数的包含文件,
ex。如此形成astring。如何做这个我的.NET?

在我下面的测试代码中,我提交一个带有文本框的表单,
使用函数format_string"改变价值。我想
也喜欢在其他脚本中使用这个函数,所以需要将
代码放在另一个文件中,并包含它,怎么样?

如果有人可以,我会很感激改变我的测试代码,以
告诉我如何做到这一点。

Thx ..

test.aspx
------ ------------
<%@ page language =" vb"继承= QUOT;试验" SRC =" test.vb" %>
< html>
< head>
< / head>

< body>
< form id =" ;试验"方法= QUOT;交" runat =" server">
< asp:textbox id =" sometext"文本= QUOT;" RUNAT = QUOT;服务器" />
< asp:button id =" submit"文本= [提交"
onclick =" test_me" runat =" server" />
< / form>
< / body>
< / html>
---------------- -

test.vb
------------------
进口系统
Imports System.Web。 UI公共类测试:继承页面
sub test_me(ByVal Sender As Object,ByVal E As
EventArgs)将某些文本作为字符串dim
sometext = format_string(Request。表格(sometext))
结束子

函数format_string(值为字符串)as string
return"!" &安培;价值与价值!
结束职能
结束课
------------------

-----Original Message-----
I''m new in the .NET world, so sorry if this is a faq. In classic ASP Ioften use a include file with some standard functions, ex. formating astring an so. How do a do this i .NET ??

In my test code below, I submit a form with a textbox, use thefunction "format_string" to change the value. I would like to use thisfunction in other scripts also, so need to place the code in anotherfile, and include it, how ?

I''ll appreciate if someone could change my test code, to show me theright way to do it.

Thx..

test.aspx
------------------
<%@ page language="vb" inherits="test" src="test.vb" %>
<html>
<head>
</head>

<body>
<form id="test" method="post" runat="server">
<asp:textbox id="sometext" text="" runat="server" />
<asp:button id="submit" text="submit" onclick="test_me"runat="server" />
</form>
</body>
</html>
------------------
test.vb
------------------
Imports System
Imports System.Web.UI

public class test : inherits page
sub test_me(ByVal Sender As Object, ByVal E As EventArgs) dim sometext as string
sometext = format_string(Request.Form("sometext"))
end sub

function format_string(value as string) as string
return "!" & value & "!"
end function
end class
------------------

.



最简单的方法是创建一些实用程序类。


public class StringUtilities

{

公共静态字符串FormatString(string s)

{

字符串结果;


//做点什么

返回结果;

}

}

然后在代码隐藏中你只是使用课程:


private void Page_Load(...)

{

string s =" Hello 123" ;;

s = StringUtilities.FormatString; s />
}


我希望这有帮助

Hugo
The easiest way would be to make some utility classes.

public class StringUtilities
{
public static string FormatString(string s)
{
string result;

//Do something
return result;
}
}
And then in the code-behind you just use the class:

private void Page_Load(...)
{
string s="Hello 123";
s=StringUtilities.FormatString(s);
}

I hope this helps
Hugo


>最简单的方法是制作一些实用程序类。


感谢您的回复....我喜欢使用实用程序类的想法。

我把这段代码放在ex中。 " StringUtilities.vb",并将其放在共享的

包含文件夹中

-----
> The easiest way would be to make some utility classes.

Thanks for your reply.... I like the idea with a "utility class".
I put this code in ex. "StringUtilities.vb", and place it in a shared
include-folder
-----
public class StringUtilities
{
公共静态字符串FormatString(string s)
{
字符串结果;

//做点什么
返回结果;
}
}
-----


我的代码隐藏代码(test.vb)如何了解该类

" ; StringUtilities" ??

----- private void Page_Load(...)
{s /> string s =" Hello 123";
s = StringUtilities.FormatString (s);
}
public class StringUtilities
{
public static string FormatString(string s)
{
string result;

//Do something
return result;
}
} -----

How do my codebehind code (test.vb) know about the class
"StringUtilities" ??
----- private void Page_Load(...)
{
string s="Hello 123";
s=StringUtilities.FormatString(s);
}



-----


-----


这篇关于包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆