2009-06-23 6 views
19

.aspx(VB)ページに渡されるGET(URL)変数を取得する最も簡単で標準的な方法は何ですか?場合、Request.QueryStringコレクションASPXのURLからGET変数を取得

+0

GETポストバック値をループするときのSOの例を次に示します。 [http://stackoverflow.com/questions/562943/looping-through-a-request-querystring-in-vb-net](http://stackoverflow.com/questions/562943/looping-through-a-request- querystring-in-vb-net) – Zachary

答えて

43

+0

[]を使用しているときに構文エラーが発生しましたが、@を使用しているときには構文エラーが発生します。 –

+1

@ClayNicholsと同じです。 'Request.QueryString [" hello "]'は動作しません。 'Request.QueryString(" hello ")'はそうです。 – tresf

7

ルックあなたは以下を使用することができます:あなたがパスを持っている場合

http://www.whatever.com?hello=goodbye&goodbye=hello 

string value = Request.QueryString("hello") 

値はさようなら

または

foreach(string key in Request.QueryString) 
{ 
    Response.write(Request.QueryString[key]) 
} 
0

次のようになります。

www.stackoverEvan.com/question/directory-lookup.asp?name=Evan&age=16 

そうした場合:

Hi , <%= Request.QueryString("name") %>. 
Your age is <%= Request.QueryString("age") %>. 

出力:

ようこそ、エヴァンを。あなたの年齢は16

である。しかし、あなたはそれがVBでです指定するよう最適な方法は次のようになります:

パス:

http://localhost/script/directory/NAMES.ASP?Q=Evan&Q=Bhops 

コード:

--- Names.asp --- 
<% 
    For Each item In Request.QueryString("Q") 
    Response.Write Request.QueryString("Q")(item) & "<BR>" 
    Next 
%> 

出力:

Evan
Bhops

関連する問題