{"id":163,"date":"2010-07-31T12:07:00","date_gmt":"2010-07-31T06:37:00","guid":{"rendered":"https:\/\/ashokaon.tech\/blog\/?p=163"},"modified":"2020-07-18T01:17:06","modified_gmt":"2020-07-17T19:47:06","slug":"request-querystring-tip","status":"publish","type":"post","link":"https:\/\/ashokaon.tech\/blog\/request-querystring-tip\/","title":{"rendered":"A tip when working with QueryStrings"},"content":{"rendered":"<p><span style=\"font-size: 10px;background-color:#FFFF99;display:block\">(Note: This blog post was originally published under my old domain(codesmiles.com), <a href=\"http:\/\/codesmiles.com\/post\/request-querystring-tip.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. <a href=\"https:\/\/web.archive.org\/web\/2010*\/http:\/\/www.codehappiness.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Web Archive link<\/a>.<\/span><br \/>\nWe still use QueryStrings for many reasons even though we have other methods to deal with HTTP requests to web applications. And when working with QueryStrings, I hate to type Request.QueryString(\u201cblah\u201d), Request.QueryString(\u201cblahblah\u201d), Request.QueryString(\u201cblahblahblah\u201d), etc., again and again when I need to. This is more tiring if there are more number of QueryString items to deal with.<\/p>\n<p>If you note, Request.QueryString is actually a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.collections.specialized.namevaluecollection.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">NameValueCollection<\/a>. So in suitable situations I would love to use a NameValueCollection object with a short name instead of Request.QueryString(\u201cblah\u201d) \ud83d\ude09 as shown below. This saves time and provides a little better coding experience.<\/p>\n<pre class=\"brush: c-sharp;\">NameValueCollection q = Request.QueryString;\r\n\r\nResponse.Write(\"name\" + q[\"name\"]);\r\nResponse.Write(\"address1\" + q[\"address1\"]);\r\nResponse.Write(\"address2\" + q[\"address2\"]);\r\nResponse.Write(\"city\" + q[\"city\"]);\r\nResponse.Write(\"country\" + q[\"country\"]);<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. We still use QueryStrings for many reasons even though we have other methods to deal with HTTP requests to web applications. And when working with QueryStrings, I hate to type Request.QueryString(\u201cblah\u201d), Request.QueryString(\u201cblahblah\u201d), Request.QueryString(\u201cblahblahblah\u201d), etc., again<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[17],"_links":{"self":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/163"}],"collection":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":2,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":304,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/163\/revisions\/304"}],"wp:attachment":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}