给一个按钮加上javascript的prompt方法脚本
让客户输入一些信息
而获取的信息内容如何传到asp.net的后台程序中

解决方案 »

  1.   

    js传值到后台当然要用xmlhttp了!
      

  2.   

    //获取产品id
    var ProductID = document.all.txtProductID.value;  
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    //alert("AccountPrice.aspx?strPrice="+str+"&ProductID="+ProductID+"&temp=" + Math.random());
    //加了个随机参数temp防止叶面缓存
    xmlhttp.open("get","AccountPrice.aspx?strPrice="+str+"&ProductID="+ProductID+"&temp=" + Math.random(), false);
    xmlhttp.send();
    var result; 
    result= xmlhttp.responseText; 
    xmlhttp = null;
      

  3.   

    AccountPrice.aspx就和平时我们获取参数那样就可以了,Request["productid"].
    再Response.Write你想要的结果result= xmlhttp.responseText;
    这是前台得到后台返回来的东西记得把AccountPrice.aspx多余的html都删掉,只留这些就行了
    <%@ Page language="c#" Codebehind="AccountPrice.aspx.cs" AutoEventWireup="false" Inherits="SF.Price.AccountPrice" %>
    要不然result会把那些body,html都获取到!
      

  4.   

    我现在是想通过prompt方法把输入对话框的值传到后台
    老大 你这个是干吗的 没看懂 呵呵
      

  5.   

    放一个隐藏域!runat=server
    如叫HF以下是js代码,我没试
    function(){
      var result=window.prompt();
      hf.value=result;
     
    }这样你就可以在后台读取HF的值
      

  6.   

    ActiveXObject是不错 但是出于安全问题 有时候会无法创建的建议使用 隐藏域-〉然后runat=server -> 然后使用server_onchange事件(即该隐藏域值改变的时候触发后台服务端事件。)
      

  7.   

    -------------------------------------------aspx.cx
    private void Page_Load(object sender, System.EventArgs e)
    {
       if(hf.Value!=null)
        {
         TextBox1.Text =hidetext.Value.ToString();
        }

       Button1.Attributes["onClick"]="var result=window.prompt(); hidetext.value=result;";
    }
    ------------------------------------------ aspx文件中添加隐藏宇
    <input id="hidetext" type="hidden" runat="server">