试验中发现,当form的method属性设置为get时,action(action='default.ashx?a=123')
中带的参数总是被覆盖(a=123被覆盖掉丢失),如何避免呢?
就是把method设置为post,才能使action中的自带参数传到服务器。
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 ='Handler2.ashx?funny=true' 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 string fun = context.Request["funny"]; //只有method为post时才能获取到值
25 context.Response.Write("您输入了:" + fun); 26 } 27 28 public bool IsReusable { 29 get { 30 return false; 31 } 32 } 33 34 }