效果:
输入用户名点击提交,输出“用户名你好”然后还有原来的表单
代码:
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=hello2.ashx> <!--把结果提交到hello2.ashx-->
- <input type="text" name="username" />
- <input type="submit" value="提交" />
- </form>
- </body>
- </html>
ashx代码
- <%@ WebHandler Language="C#" Class="hello2" %>
- using System;
- using System.Web;
- public class hello2 : IHttpHandler {
- public void Proce***equest (HttpContext context) {
- context.Response.ContentType = "text/html";
- string username = context.Request["username"];
- context.Response.Write(@"<form action=hello2.ashx> <!--把结果提交到hello2.ashx-->
- <input type='text' name='username'value='"+username+@"' />
- <input type='submit' value='提交' />
- </form>"); //将html代码重新输出到客户端,绘画出原来表单。
- //注意在【name=username】后面添加【'value='"+username+@"'】实现用户名输入后提交后还存在
- context.Response.Write(username + "你好");
- }
- public bool IsReusable {
- get {
- return false;
- }
- }
- }
转载于:https://blog.51cto.com/zjking/611509