如何使用javascript传递查询字符串并在asp.net的代码隐藏页面中使用它?

时间:2014-05-13 06:50:05

标签: javascript asp.net query-string

目前我正在使用JavaScript打开如下所示的对话框中的页面。我通过将查询字符串加密到列表页面来传递它。

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");
        }

    } 

现在在页面后面的代码我正在使用这段代码:

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();

现在使用Querystring[0]时,我只获取前十进制值,就像我在文本框中输入的值是13.33一样,那么我在列表页面上只获得13。有谁能够帮我?

谢谢。

2 个答案:

答案 0 :(得分:3)

在param变量上使用escape,如下所示

window.showModalDialog("list.aspx?id=" + escape(param), Obj, "dialogWidth:800px; dialogHeight:500px; dialogLeft:252px; dialogTop:120px; center:yes");

或encodeURI

window.showModalDialog(encodeURI("list.aspx?id=" + param), Obj, "dialogWidth:800px; dialogHeight:500px; dialogLeft:252px; dialogTop:120px; center:yes");

答案 1 :(得分:0)

使用encodeURIComponent()对您的网址进行编码,然后再将其发送到服务器。

http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp

编辑:添加了指向源的链接。

相关问题