IsPostBack实现

 1 <%@ WebHandler Language="C#" Class="Handler2" %>
 2 
 3 using System;
 4 using System.Web;
 5 
 6 public class Handler2 : IHttpHandler {
 7     
 8     public void ProcessRequest (HttpContext context) {
 9         //context.Response.ContentType = "text/plain";
10         //context.Response.Write("Hello World");
11         //根据请求中是否包含名为IsPostBack的值
12         //判断是第一次请求还是表单提交
13         if (string.IsNullOrEmpty(context.Request.Form["IsPostBack"]))
14         {
15             context.Response.Write(@"<html><head><title></title><head><body><form action ='' method='post' id='myform'><input type='text' name='txtname'></input>
16                         <input type='hidden' name='Ispostback' value='1'></input>   
17                         <input type='submit' value='tijiao'></input></form></body></html> ");
18         }
19         else
20         {
21             string txtname = context.Request["txtName"];
22             context.Response.Write("您输入了:" + txtname);
23         }
24     }
25  
26     public bool IsReusable {
27         get {
28             return false;
29         }
30     }
31 
32 }

 

posted @ 2013-05-27 20:22  Big.Eagle  阅读(133)  评论(0编辑  收藏  举报