效果:

输入用户名点击提交,输出“用户名你好”然后还有原来的表单

 

代码:

html

 


  
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5.     <title>无标题页</title> 
  6. </head> 
  7. <body> 
  8. <form action=hello2.ashx> <!--把结果提交到hello2.ashx--> 
  9. <input type="text" name="username" /> 
  10. <input type="submit" value="提交" /> 
  11. </form> 
  12. </body> 
  13. </html> 

ashx代码

 

 


  
  1. <%@ WebHandler Language="C#" Class="hello2" %> 
  2.  
  3. using System; 
  4. using System.Web; 
  5.  
  6. public class hello2 : IHttpHandler { 
  7.      
  8.     public void Proce***equest (HttpContext context) { 
  9.         context.Response.ContentType = "text/html"
  10.         string username = context.Request["username"]; 
  11.         context.Response.Write(@"<form action=hello2.ashx> <!--把结果提交到hello2.ashx--> 
  12. <input type='text' name='username'value='"+username+@"' /> 
  13. <input type='submit' value='提交' /> 
  14. </form>");                                                    //将html代码重新输出到客户端,绘画出原来表单。 
  15.                                                              //注意在【name=username】后面添加【'value='"+username+@"'】实现用户名输入后提交后还存在 
  16.         context.Response.Write(username + "你好"); 
  17.     } 
  18.      
  19.      
  20.   
  21.     public bool IsReusable { 
  22.         get { 
  23.             return false
  24.         } 
  25.     } 
  26.