点击按钮后台可以取到值,但如果用在INPUT 中用回车激发按钮事件 后台总是取不到值
比如我选择下拉框的第二个值 然后点击按钮 会将 1 传过去
但如果用回车 却没有值?
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script language="javascript" type="text/javascript">
        function GetMethod()
        {
           var val=document.getElementById("select").value;
           location.href="Default.aspx?id="+val;
        }
        
        function inputKeyDown()
        {
            if(event.keyCode==13)
            {
                document.getElementById("Button1").click();
            }
        }
    
    </script>
</head>
<body>
    <form id="form1" method="get">
    <div>
    
     <input id="Text1" type="text"  onkeydown="inputKeyDown()" />
        <input id="Button1" type="button" value="button"  onclick="GetMethod()"/>
        <select id="select">
            <option  value="0" selected="selected">zonghe</option>
            
            <option value="1">wenzhang</option>
            <option value="2">chanpin</option>
                        
        </select>
    </div>
    </form>
</body>
</html后台using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("过来了");
        if(!IsPostBack)
        {
            if(Request["id"]!=null)
            {
                Response.Write(Request["id"].ToString()+"</br>");
            }            if(Request.Params["id"]!=null)
            {
                Response.Write(Request["id"].ToString() + "</br>");
            }
            
        }
    }
}

解决方案 »

  1.   

    document.getElementById("Button1").click();
    在Button1_Click中
    Request.Form取值
      

  2.   


    试过了
    Request.Form["id"]!=null
    空的
      

  3.   

    回车将导致form自动提交,即使你没有GetMethod()与inputKeyDown()方法.所以尽管getMethod()执行了,但其中的location.href命令将被form提交命令掩盖(或忽略,或者说form提交优先),当然getMethod()中的其它命令会被执行的。也就是说,你的location.href没有被执行。如果你想达到你的要求,又不作大的改动,你可以将
    <select id="select">变为<select id="select" name="id">,即增加name属性,值为"id"
      

  4.   

    另一个方法也可以:
    去掉<form id="form1" method="get">
    以及</form>这样就不用给<select id="select">添加name属性了。
      

  5.   

    function inputKeyDown()
    {
        if(event.keyCode==13)
        {
             event.keyCode=9;         document.getElementById("Button1").click();
        }
     }
      

  6.   

    inputKeyDown()中新加一句:event.keyCode=9;function inputKeyDown()
    {
        if(event.keyCode==13)
        {
             event.keyCode=9;
             document.getElementById("Button1").click();
        }
    }
      

  7.   

    去掉FORM标记后可以了,
    但添加NAME属性好像不行,添加NAME属性后还需要该其他地方?
      

  8.   


    恩,可以了 不过为什么加上event.keyCode=9;
    后就可以了?
      

  9.   

    当你点击回车的时候,event中不去执行回车这个事件