admin管理员组

文章数量:1405131

Currently I am opening a page in dialog box as shown below using 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. Can anybody help me?

Thank you.

Currently I am opening a page in dialog box as shown below using 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. Can anybody help me?

Thank you.

Share Improve this question edited May 13, 2014 at 6:54 István 5,12710 gold badges40 silver badges67 bronze badges asked May 13, 2014 at 6:50 RachitSharmaRachitSharma 5894 gold badges13 silver badges32 bronze badges 3
  • What's the final URL formed after calling Popup? – Haseeb Asif Commented May 13, 2014 at 6:53
  • @HaseebAsif : sorry my mistake its this one localhost:6651/random/Page/list.aspx?id= <>#>> – RachitSharma Commented May 13, 2014 at 6:57
  • You need to URL encode your values. w3schools./tags/ref_urlencode.asp – Elad Lachmi Commented May 13, 2014 at 6:59
Add a ment  | 

2 Answers 2

Reset to default 3

Use escape on the param variable as follows

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

or 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.

http://www.w3schools./jsref/jsref_encodeuriponent.asp

Edit: Added link to source.

本文标签: How to pass a querystring with javascript and use it in codebehind page in aspnetStack Overflow