asp.net(c#)中,Response.End()有无存在必要?

mohugomohu 2008-04-22 03:00:14
以前学C#的时候,都是用"return"
现在弄Web,觉得没必要用Response.End()
它们有什么区别?请指教。
...全文
744 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
avrilxu 2008-04-22
  • 打赏
  • 举报
回复
return是用在方法中的
表示跳出方法
response.end则是停止运行代码,直接输出
停止的应该是js代码吧
grearo 2008-04-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 mohugomohu 的回复:]
引用 1 楼 grearo 的回复:
Response.End()
是停止页面html代码的书写
return
是返回停止该函数操作

你的意思是:就算用了Response.End(),下面的代码继续执行(除了页面html代码的书写)?
[/Quote]

Response.End()
是停止对Html中
<body>内容的输出


Return是建立好了各个组件,停止数据处理
mylibin 2008-04-22
  • 打赏
  • 举报
回复
return是用在方法中的
表示跳出方法
response.end则是停止运行代码,直接输出
mohugomohu 2008-04-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 grearo 的回复:]
Response.End()
是停止页面html代码的书写
return
是返回停止该函数操作
[/Quote]
你的意思是:就算用了Response.End(),下面的代码继续执行(除了页面html代码的书写)?
grearo 2008-04-22
  • 打赏
  • 举报
回复
例如:
protected void Page_Load(object sender, EventArgs e)
{
Response.End();

}

输出:




<!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><title>
无标题页
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGSr3Z4GoFkkYIkS3gjEDZgu5z75Fg==" />
</div>

<div>

</div>
</form>
</body>
</html>




protected void Page_Load(object sender, EventArgs e)
{
return;
}

输出:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312"></HEAD>
<BODY></BODY></HTML>



whoami333 2008-04-22
  • 打赏
  • 举报
回复
这两个好像没有什么关系的吧。response.end应该表示应答结束的吧。
grearo 2008-04-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 grearo 的回复:]
Response.End()
是停止页面html代码的书写
return
是返回停止该函数操作
[/Quote]
Response.End()
是停止服务器端页面代码输出
grearo 2008-04-22
  • 打赏
  • 举报
回复
Response.End()
是停止页面html代码的书写
return
是返回停止该函数操作

111,095

社区成员

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

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

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