[英]How to pass a querystring with javascript and use it in codebehind page in asp.net?
Currently I am opening a page in dialog box as shown below using JavaScript. 目前我正在使用JavaScript打开如下所示的对话框中的页面。 I am passing a query string by encrypting it to the list page .
我通过将查询字符串加密到列表页面来传递它。
function Popup() {
if (document.getElementById("<%= Amount.ClientID %>").value != "") {
var xorKey = 13;
var Obj = window;
var id = document.getElementById("<%= id.ClientID %>").value + "-" + document.getElementById("<%= Amount.ClientID %>").value;
var result = "";
for (i = 0; i < id.length; ++i) {
param += String.fromCharCode(xorKey ^ id.charCodeAt(i));
}
window.showModalDialog("list.aspx?id=" + param, Obj, "dialogWidth:800px; dialogHeight:500px; dialogLeft:252px; dialogTop:120px; center:yes");
}
}
Now on code behind page I am using this code : 现在在页面后面的代码我使用这个代码:
string id = Request.QueryString[0].ToString();
StringBuilder inSb = new StringBuilder(id);
StringBuilder outSb = new StringBuilder(id.Length);
char c;
for (int i = 0; i < id.Length; i++)
{
c = inSb[i];
c = (char)(c ^ 13); /// remember to use the same XORkey value you used in javascript
outSb.Append(c);
}
string[] idvalue = outSb.ToString().Split('-');
id = idvalue[0].ToString();
Now when using the Querystring[0]
I am only getting the pre decimal values like if the value I type in textbox is 13.33
, then I am on the list page getting only 13
. 现在当使用
Querystring[0]
我只得到前十进制值,就像我在文本框中键入的值是13.33
,然后我在列表页面上只得到13
。 Can anybody help me? 有谁能够帮助我?
Thank you. 谢谢。
Use escape on the param variable as follows 在param变量上使用escape,如下所示
window.showModalDialog("list.aspx?id=" + escape(param), Obj, "dialogWidth:800px; dialogHeight:500px; dialogLeft:252px; dialogTop:120px; center:yes");
or encodeURI 或encodeURI
window.showModalDialog(encodeURI("list.aspx?id=" + param), Obj, "dialogWidth:800px; dialogHeight:500px; dialogLeft:252px; dialogTop:120px; center:yes");
Use encodeURIComponent() to encode your url before sending it to the server. 在将url发送到服务器之前,使用encodeURIComponent()对其进行编码。
http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp
Edit: Added link to source. 编辑:添加了源的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.