新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > Asp.net教程 > 正文:坚持学asp.net——(十)

坚持学asp.net——(十)

新客网 XKER.COM 2004-09-23 来源: 收藏本文
一、命名空间

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

下面列举在使用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()


收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐