效果:

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

 

asp.net学习日记之一般处理程序1-1_第1张图片

代码:

html

 

   
   
   
   
  1. > 
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4. <head> 
  5.     <title>无标题页title> 
  6. head> 
  7. <body> 
  8. <form action=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(@"  
  12. 'text' name='username'value='"+username+@"' /> 
  13. 'submit' value='提交' /> 
  14. ");                                                    //将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.