[RESOLVED]decimal separator and querystring

Hi all:

I try pass via querystring a variable var1=’121.1′ and read this var1 in another page. I don’t read 121.1. When I see the source code I have

crttcuentas=importe+pagos%7e121%2c00

 If I pass another variable var2=’2′, it is ok, no problem because it doesn’t have any decimal separator. The source code is

npublicaciones+like+%27%252%25%27

I do server.urlencode before passing the variable, and server.urldecode to read this variable

Can u help me to solve it?

Thanks in advance

Volar

crttcuentas=importe+pagos%7e121%2c00

%2c stands for , separator.

To decode use
Server.UrlDecode

Are you passing this QueryString value through Javascript such as using something like the following : 

window.location.href = "YourTargetURL?key=121.1";

or are you using a server-side redirection : 

Response.Redirect("YourTargetURL?key=121.1");

Regardless of how you are performing it – you should have no problems passing it across like that (or accessing it by the actual QueryString key itself) : 

//The loading event of your Target Page
protected void Page_Load(object sender, EventArgs e)
{
      //Check if your Key exists
      if(Request.QueryString["key"] != null)
      {
            //Parse it if it does (your logic here)
            double yourValue = double.Parse(Request.QueryString["key"]);
      }            
}

Hi again:

I am passing via window.open(….

I can’t solve it

Thanks a lot

Passing it through window.open() should function the exact same as setting it through either of the other methods. 

Could you post the code (for setting it client-side) and how you are attempting to access it (either client-side or server-side)?

Hi again

I did it. I pass this sentence via window.open

importepagos+like+%27%25121%25%27

When reading it with server.urldecode I get importepagos like ’1.1%’ instead of the expected importpagos like ‘%121.1%’

I expected the latter because I pass importepagos like ‘%121.1%’

Can u explain me what is happening? Thanks in advance

The code is large to put here

I pass the variable,strcondicion, doing

lblvarios.Text = Replace(lblvarios.Text, strdatos, "&cnd" & tabla & "=" & Server.UrlEncode(strcondicion) & "&crt" & tabla & "=" & Server.UrlEncode(strcriterios) & IIf(blnfiltrar, "&flt" & tabla & "=true", ""))

I read doing

ViewState("condiciontcuentas") = Server.UrlDecode(Request.QueryString("cndtcuentas"))

cndtcuentas =importepagos like ‘%121.1%’

Thanks for any help

Have you tried passing it without using the Server.UrlEncode() and Server.UrlDecode() methods?

Hi:

Exactly, I tried without urlencode and urldecode. Now it works fine

I wonder why. Thanks

I believe it is an issue with the decimal place (it may be assuming that it part of a URL similar to an extension or subdomain) and it is not encoding it properly, which causes it to be missed when the values are decoded.

Volar

I wonder why. Thanks

ASP.NET automatically calls UrlDecode() when you access a property by key index (i.e. (Request.QueryString["key"]).

Hi again:

But a problem arise when I have characters like ~

Or simply white spaces

If I  don’t do the urlencode, sometimes the url becomes NaN and get me an error of page not found

I hve to put server.urlencode

How to solve it now? replacing the white spaces by +, doing the urlencode mannually?

Thanks

When you create an uri, use Server.UrlEncode

http://asp-net-example.blogspot.de/2009/01/aspnet-urlencode-method-example-how-to.html

Regarding "+". UrlEncode could encode space as "%20" instead of "+". Both %20 and + are valid ways of encoding a space. If you want to get + you can try replace it manually s.replace("%20", "+")

Leave a Reply