当前位置: 代码迷 >> ASP.NET >> 如何从html到asp.net传递参数
  详细解决方案

如何从html到asp.net传递参数

热度:3216   发布时间:2013-02-25 00:00:00.0
怎么从html到asp.net传递参数?
我是这样做的,但服务器始终取不到

html:
<form   action= "queryzhan.aspx "   name= "zhanzhan "   method= "post ">
<div>
出发地: <input   type= "text "   size= "10 "   maxlength= "10 "     class= "url "   id= "chufa "   /> &nbsp;&nbsp;   目的地: <input   type= "text "   size= "10 "   maxlength= "10 "     class= "url "   id= "zhongdian "   /> <input   type= "submit "   value= "查询 "   id= "sub "     />
</div>
</form>

asp.net里面通过以下两种方法都取不到:
System.Web.HttpContext.Current.Request.Form[ "zhongdian "]
System.Web.HttpContext.Current.Request.QueryString[ "zhongdian "]

------解决方案--------------------------------------------------------
方法1
html method= "get "

<form action= "queryzhan.aspx " name= "zhanzhan " method= "get " ID= "Form1 ">
<div>
出发地: <input type= "text " size= "10 " maxlength= "10 " class= "url " id= "chufa " NAME= "chufa "/> &nbsp;&nbsp; 目的地: <input type= "text " size= "10 " maxlength= "10 " class= "url " id= "zhongdian " NAME= "zhongdian "/> <input type= "submit " value= "查询 " id= "sub " NAME= "sub "/>
</div>
</form>

那么
aspx文件中 可以用QueryString得到
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Request.QueryString[ "zhongdian "]);

}
------解决方案--------------------------------------------------------
晕,
input的name属性等于zhongdian,而不是id.
  相关解决方案