9-17ASP第一节
来源:互联网 发布:计算机java二级考试 编辑:程序博客网 时间:2024/05/29 05:55
css html js jquery >>>>>>>都是在浏览器中
ASP>>>>>>>>>>>>>>后台服务器中
在asp文件中的这些<asp:TextBox ID="TextBox1....">标签
和以前我们写的<input type="text"....>其实就是一个东西
因为在执行的时候,服务器都会把<asp:TextBox...>翻译成html.因为浏览器只认识html
WebSite=====网站
WebApplication======web应用
string username=context.Request[UserName];//获取用户提交过来的
context.Response.ContentType="text/html";//响应的数据
context.Response.ContentType="";
context.Response.Weite(username);
context.Response.Weite(":你好啊");
这就是asp.net的工作原理 。
提交给那个服务端的处理程序。用form action属性给出
提交给服务器的控件一定要有name属性,这id可以随便是什么服务器只认识
今天的例题:
例一----------------------------------------ashx里面
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
namespace WebApplication2
{
/// <summary>
/// helloword2 的摘要说明
/// </summary>
public class helloword2 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string fulPath = context.Server.MapPath("helloword2.htm");//得到helloword.html的全路径
string htmlContent= File.ReadAllText(fulPath );//得到helloword.html的内容
context.Response.Write(htmlContent);//把helloword.html的内容的输入来、、、、
string ispostback= context.Request ["ispostback"];//得到表单的value值
if (ispostback == "true")
{
context.Response.Write("提交进去");
}
else
{
context.Response.Write("直接进去");
}
//string username=context.Request ["UserName"];
//if (string.IsNullOrEmpty(username))
//{
// context.Response.Write("直接进去");
//}
//else
//{
// context.Response.Write("提交进去");
//}
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
-------------------------------------html里面
<!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 action ="helloword2.ashx">
<input type="hidden"name="ispostback" value =true />
姓名:<input type="text" name="UserName" /><input type ="submit" value ="提交" />
</form>
</body>
</html>
例2
------------------------ashx中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication2
{
/// <summary>
/// helloword 的摘要说明
/// </summary>
public class helloword : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string username=context.Request["UserName"];//获取用户提交过来的name为UserName的表单的值
context.Response.ContentType = "text/html";//响应的数据时html
context.Response.Write(@"姓名:<input type='text' name='UserName'value='"+username+@"'/><input type ='submit' value ='提交' >");
context.Response.Write(username);//将表单值写回到浏览器中
context.Response.Write(":你好啊");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
----------------------------html中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication2
{
/// <summary>
/// helloword 的摘要说明
/// </summary>
public class helloword : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string username=context.Request["UserName"];//获取用户提交过来的name为UserName的表单的值
context.Response.ContentType = "text/html";//响应的数据时html
context.Response.Write(@"姓名:<input type='text' name='UserName'value='"+username+@"'/><input type ='submit' value ='提交' >");
context.Response.Write(username);//将表单值写回到浏览器中
context.Response.Write(":你好啊");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
- 9-17ASP第一节
- 第一节
- 第一节
- 第一节
- 第一节
- 第一节
- ASP.NET MVC3 快速入门-第一节 概述
- ASP.NET MVC3 快速入门-第一节 概述
- ASP.NET MVC3书店--第一节+概述
- ASP.NET MVC3 快速入门-第一节 概述
- ASP.NET MVC3 快速入门-第一节 概述
- 实训课第一节 创建ASP.NET应用程序
- ASP.NET MVC3快速入门——第一节、概述
- ABP+AdminLTE+Bootstrap Table权限管理系统第一节--使用ASP.NET Boilerplate模板创建解决方案
- 第一节 IContextMenu
- 登场!第一节
- bsci第一节
- XML第一节
- C# 删除word的指定页
- 一条没有鱼鳔的鱼
- 单身快乐(致一个人的情人节)
- 感悟
- 管道实现处理分工,实现两数想加 linux环境高级编程
- 9-17ASP第一节
- 经典数据结构B+树
- NSArray中数据排序方法
- 原子操作及其重要性
- 关于爱情
- PHP生成条形码
- linux wget
- cocos2d精灵与动画详解
- poj2635The Embarrassed Cryptographer(数论)(解题报告)