你这个逻辑有点混乱, 服务器的代码在输出HTML时已经执行了. 你的保存按钮是个button还是submit?

解决方案 »

  1.   

    说白了,我就是想点一个按钮,然后保存一点东西罢了因为不懂JavaScript,老大门能否给点代码?谢谢先
      

  2.   

    那你就用form提交,不用javascript也行, 按钮type="submit"
      

  3.   

    使用AJAX吧,FIREFOX可能不支持。
    <!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 type="text/javascript">
    var xmlhttp;
    function Validation()
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        var name=document.getElementById("Text1");
        xmlhttp.open("Post","AJAXProcessor.aspx?name="+name.value);
        xmlhttp.onreadystatechange=OnMessageBack;
        xmlhttp.send(null);
    }
    function OnMessageBack()
    {
        if(xmlhttp.readystate==4&&xmlhttp.status==200)
        {
            document.write(xmlhttp.responsetext);
        }
    }
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
     
            <input id="Text1" type="text" /><input id="Button1" type="button" value="button" onclick="Validation();" />
        </div>
        </form>
    </body>
    </html>
    string ReAction = this.Request.QueryString["Action"];//这是你从页面上请求来的值
    SqlConnection Conn = new SqlConnection(“连接字符串");
    Conn.Open();
    SqlCommand Cmd = new SqlCommand();
    Cmd.Connection = Conn;
    Cmd.CommandText = "更新字符串";
    Cmd.ExecuteNonQuery();
    Conn.Close();
      

  4.   

    请问一下,上面的代码放到jsp里面可以跑吗
    还有个问题,用户输入的东西保存到哪里去了?谢谢
      

  5.   

    TO:5楼
    完善5楼的。var xmlHttp=false;
    try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
    try
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e2)
    {
    xmlHttp=false;
    }
    }
    if(!xmlHttp && XMLHttpRequest!='undefined')
    {
    xmlHttp=new XMLHttpRequest();
    }另外采取post提交数据时,在处理页面用Request.Form[]接受数据...