如何在代码隐藏中访问javascript querystring?

问题描述:

即时通讯从一个页面以aspx发送一个值到另一个页面,如下所示。如何在代码隐藏中访问javascript querystring?

了window.location = “test1.aspx?ID = 1”

如何在代码隐藏访问该值或Global.asax中?

你可以检索来自Request对象ID参数背后代码:

protected void Page_Load(object sender, EventArgs e) 
{ 
    string id = Request["id"]; 
    // do something with the id 
} 

你也必须解决您的JavaScript,因为你是分配的网址是无效的。你有一个额外+字符应该被删除:

window.location.href = 'test1.aspx?id=1'; 
+0

是否有可能在global.asax中访问相同的内容? – user1357872 2012-07-08 19:13:36

+0

Global.asax是一个文件。在这个文件的哪个事件中,你是否需要访问id查询字符串?你可以在'Application_BeginRequest'事件中访问它。 – 2012-07-08 19:14:07

+0

@ user1357872:您可以在'HttpContext'范围内的任何'Request'对象中访问任何内容。看看'System.Web.HttpContext.Current':http://msdn.microsoft.com/en-us/library/system.web.httpcontext.current.aspx – David 2012-07-08 19:16:34

离开+登出并使用Request.QueryString对象。

window.location="test1.aspx?id=1" 

string v = Request.QueryString["id"];