javascript 通过javascript将查询字符串从一个页面传递到另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23213499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 00:32:54  来源:igfitidea点击:

Passing querystring from one page to another through javascript

javascriptasp.netquery-string

提问by King of kings

I have two different pages. I want to send querystring from one to another. below is my sample code that i have tried

我有两个不同的页面。我想将查询字符串从一个发送到另一个。下面是我尝试过的示例代码

window.location.search = 'id='+hidposid.value; 
window.location.href="editviewposition.aspx";

in another page i retrieve the value

在另一个页面中,我检索了该值

cookie1 = HttpContext.Current.Request.QueryString("id") ' returns ""

回答by Richa Jain

<script type="text/javascript">
    $(function () {
        $("#btnQueryString").bind("click", function () {
            var url = "Page2.htm?name=" + encodeURIComponent($("#txtName").val()) + "&technology=" + encodeURIComponent($("#ddlTechnolgy").val());
            window.location.href = url;
        });
    });
</script>

<input type="button" id="btnQueryString" value="Send" />

Hope this will help u..

希望这会帮助你..

回答by Steven

I think I'd rather do something like

我想我宁愿做类似的事情

window.location.href= 'editviewposition.aspx?id=' + hidposid.value;

Or is there a reason this is not possible?

或者有什么原因这是不可能的?

回答by Mohamed Abbas

Here you are passing query string not cookies Get it like

在这里你传递的是查询字符串而不是 cookie 得到它像

window.location.search = '?id='+hidposid.value;
window.location.href="editviewposition.aspx";

and then in code behind

然后在后面的代码中

HttpContext.Current.Request.QueryString("id")