在javascript中用prompt方法获取的内容如何传到asp.net的后台程序中 给一个按钮加上javascript的prompt方法脚本让客户输入一些信息而获取的信息内容如何传到asp.net的后台程序中 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 js传值到后台当然要用xmlhttp了! //获取产品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; 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都获取到! 我现在是想通过prompt方法把输入对话框的值传到后台老大 你这个是干吗的 没看懂 呵呵 放一个隐藏域!runat=server如叫HF以下是js代码,我没试function(){ var result=window.prompt(); hf.value=result; }这样你就可以在后台读取HF的值 ActiveXObject是不错 但是出于安全问题 有时候会无法创建的建议使用 隐藏域-〉然后runat=server -> 然后使用server_onchange事件(即该隐藏域值改变的时候触发后台服务端事件。) -------------------------------------------aspx.cxprivate 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"> web.config里的<allow roles="Admin">, roles到底是从哪儿判断的? 关于网站服务器的最低配置的问题。 sql 搜索排序问题. 请问怎样获取单击GridView某一行的内容 .net2010在win7 64位下无法连接oracle,急! 請問我下面語句出錯在哪裡? 一个简单的问题,可就是出不来,请教? 简单连接和弹出对话框问题 单击LinkButton时,转向另外一个页面,并传递一个字符串,代码如何写?在线等! 网卡问题 datagrid按钮列问题?看看能不能实现!? 郁闷散分!!!
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;
再Response.Write你想要的结果result= xmlhttp.responseText;
这是前台得到后台返回来的东西记得把AccountPrice.aspx多余的html都删掉,只留这些就行了
<%@ Page language="c#" Codebehind="AccountPrice.aspx.cs" AutoEventWireup="false" Inherits="SF.Price.AccountPrice" %>
要不然result会把那些body,html都获取到!
老大 你这个是干吗的 没看懂 呵呵
如叫HF以下是js代码,我没试
function(){
var result=window.prompt();
hf.value=result;
}这样你就可以在后台读取HF的值
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">