1

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.

3
  • What's the final URL formed after calling Popup? Commented May 13, 2014 at 6:53
  • @HaseebAsif : sorry my mistake its this one localhost:6651/random/Page/list.aspx?id= <>#>> Commented May 13, 2014 at 6:57
  • You need to URL encode your values. w3schools.com/tags/ref_urlencode.asp Commented May 13, 2014 at 6:59

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

Comments

0

Use encodeURIComponent() to encode your url before sending it to the server.

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

Edit: Added link to source.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.