坚持学asp.net——(十)

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

asp.net中的对象

一、命名空间

只是一个形象的代号,能够粗略表达其中类的情况。

下面列举在使用asp.net创建web程序时最常用的命名空间:

System.Web;System.Web.Ui;System.IO;System.Collections;System.Diagnostics;System.Date;System.Globalization;System.Drawing;System.Xml

Response.Redirect的使用:

<script language="c#" runat="server">

void Page_Load(object source,EventArgs e){

if(!(IsPostBack)){

Button1.Text="OK";

DropDownList1.Items.Add("http://www.sohu.com");

DropDownList1.Items.Add("http://www.sina.com.cn");

DropDownList1.Items.Add("http://www.163.com");

}

}

public void Click(object o,EventArgs e){

Response.Redirect(DropDownList1.SelectedItem.Text);

}

</script>

<form runat="server">

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>

<asp:Button ID="Button1" runat="server" OnClick="Click" Text=""/>

</form>

二、asp.net的核心对象

1、Request对象:

部分属性:

ApplicationPath

Path

PhysicalApplicationPath

Browser

Cookies

IsSecureConnection

RequestType

QueryString

Url

Rawurl

UserHostName

UserHostAddress

UserLanguages

下面是一个检查这些属性的小例子:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>

<script Language="C#" runat="server">

void Page_Load(Object Src, EventArgs E)

{

if (!IsPostBack) {

if(Request.Browser.Browser=="IE")

{

if(Request.Browser.MajorVersion<6){

Label1.Text="Time to update your Ietnet Explore !";

}

else{

Label1.Text="小子很吊呀,早就用上最新的浏览器了!";

}

}

else

{

Label1.Text="Your Browser is "+Request.Browser.Browser+" !";

}

}

}

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

</head>

<body>

<asp:Label ID="Label1" runat="server" Text="" />

</body>

</html>

2、Response对象

以下几个属性和方法:

Buffer

ContentType

Cookies

Clear()

Flush()

End()

Redirect()

Write()

WriteFile()

下面是一个形象的例子:

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>无标题文档</title>

</head>

<body>

<%

for(int i=0;i<50000;i++){

Response.Write("X");

if(i%300==0)

Response.Write("<br>");

}

%>

</body>

</html>

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>无标题文档</title>

</head>

<body>

<%

Response.Buffer=false;

for(int i=0;i<50000;i++){

Response.Write("X");

if(i%300==0)

Response.Write("<br>");

}

%>

</body>

</html>

这两段代码十分想象,但是运行差别却是非常明显的。

3、server对象

MachineName

ScriptTimeOut

HtmlEncode()

HtmlDecode()

MapPath()

UrlEncode()

UrlDecode()

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航