Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,i am passing some values from one page to another page using QueryString in url, when i debug in client side and get current values which i passed from another page,
but if i debug in server side, it still showing old values which i passed at first time.

so how to get current value in QueryString from server side ?

What I have tried:

client side
JavaScript
function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};


gives correct value.

Server side
VB
Dim userName = Request.QueryString("UsrName")  '' return always old vlaue
Posted
Updated 24-Jul-18 2:07am
Comments
F-ES Sitecore 24-Jul-18 4:36am    
The parameter is probably still on the url. We don't know how you are transferring from one page to another, and we can't access your system, but Querystring doesn't "remember old values", if it is returning a value for that param it is because that param is on the current url.
Aravindba 24-Jul-18 6:52am    
hi i pass query string like this
http://localhost/web/Change.aspx?UsrName=" + Name

if i get value of query sting from Change.aspx client side gives correct result,
but from server side retrieve old values.
F-ES Sitecore 24-Jul-18 7:17am    
Well it can't so there is something else happening. How do you know it is getting "old values"? If you mean the page content hasn't been changed to reflect new data then it could be you are getting a cached version of the page.
Aravindba 24-Jul-18 23:48pm    
yes correct, but how from client side i get new values ? only from server side i get old values, which i get at first time.

1 solution

As mentioned in comments, querystrings are not remembered so you need to debug your code and find out exactly what it is doing.

When JavaScript reads the querystring it is likely after the page has loaded and is done. For example, someone goes to the page http://site.com/somepage?username=test then JavaScript can get username.

However, you have some code that you have not shown us that is then causing a post to another page and in C# you are trying to get the QueryString but the button or link or whatever that caused that page to load is not including the value in the querystring.

You'll have to debug this.
 
Share this answer
 
Comments
Aravindba 24-Jul-18 23:51pm    
yes, in page load i try to get query sting value like Dim userName = Request.QueryString("UsrName") , but it returns old value which get at first time, but if i try to retrieve from client side, i get new values.
i put log entry for writelog(userName), always return old values.
ZurdoDev 25-Jul-18 7:46am    
As I said, debug your code. You need to understand how it works. We can't see it so we can't tell you what you are doing.
Aravindba 27-Jul-18 4:09am    
hi yes, it will reload content 2 to 3 times, so remove reload content after that working fine, i mean 3 times it hit page load, but even 3 times hit page load, it must bring new values only but how show old values.
any way thanks for support
ZurdoDev 27-Jul-18 7:47am    
I can't be any more clear. It is not bringing old values. It is showing exactly what you have told it to.
Obaid Jawad 16-Apr-22 15:58pm    
same issue with me brother and I can't figure out why I have this problem. My scenario is exactly same like your method - it is calling the page from javascript method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900