How do I check if a query string has a parameter in VB.NET? I'm having a hard time adapting C# code to VB.
I'm particularly interested in determining if a value-less/key-less parameter exists.
Pseudo-Code:
If Request.QueryString.Contains("test") Then
' ...
End If
Examples:
http://example.com/mypage.aspx?test
http://example.com/mypage.aspx?test=1
http://example.com/mypage.aspx?someparam=1&test&anotherparam=2
To clarify, I don't care whether or not test
has a value. I just want to know if it is in the query string or not.
You were close. Use:
If Request.QueryString.ToString.Contains("test") Then
' ...
End If
if Request.QueryString("test").Count > 0 then
...
end if
This should address both scenarios:
<%@ Page Language="VB"%>
<%
if Request.QueryString("test")<>"" then
Response.Write ("EXISTS")
else
Response.Write ("not defined")
end if
%>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.