为什么request.querystring在ASP.NET中保存旧值 [英] Why request.querystring holding old values in ASP.NET

查看:63
本文介绍了为什么request.querystring在ASP.NET中保存旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在url中使用QueryString将一些值从一个页面传递到另一个页面,当我在客户端调试并获取我从另一个页面传递的当前值时,

但是如果我调试在服务器端,它仍然显示我第一次通过的旧值。



那么如何从服务器端获取QueryString中的当前值?



我尝试过:



客户端

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

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

Dim userName = Request.QueryString("UsrName")  '' return always old vlaue

推荐答案

如评论中所述,不会记住查询字符串,因此您需要调试代码并查找确切地知道它在做什么。



当JavaScript读取查询字符串时,它可能在页面加载完成后完成。例如,某人访问页面http://site.com/somepage?username=test然后JavaScript可以获得用户名。



但是,你有一些代码你没有向我们展示然后导致帖子到另一个页面,在C#中你试图获取QueryString,但是按钮或链接或导致该页面加载的任何内容都不包括查询字符串中的值。



你必须调试这个。
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.


这篇关于为什么request.querystring在ASP.NET中保存旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆