ACP
ACP

Reputation: 35268

Conditionally check two urls based on "Request.QueryString"

I have a page which will have these urls,

http://localhost:1218/Order-AUG17/Forms/Order.aspx?ContactName=HajaMubeen and
http://localhost:1218/Order-AUG17/Forms/Order.aspx

and in my page load i have checked this,

if (Request.QueryString["ContactName"] != "")
   //My logic
else
    //My logic

But this if condition fails for both the urls. Any suggestion.

Upvotes: 0

Views: 670

Answers (2)

anishMarokey
anishMarokey

Reputation: 11397

if you are trying with

http://localhost:1218/Order-AUG17/Forms/Order.aspx

both will be false only. because no query string is there in the URL.It comes as null

if (Request.QueryString["ContactName"] != "")
   //My logic
else
    //My logic

if you are trying with

http://localhost:1218/Order-AUG17/Forms/Order.aspx?ContactName=HajaMubeen

if (Request.QueryString["ContactName"] != "")
       //My logic
    else
        //My logic

it will consider the if condition and execute that loop.

Upvotes: 1

Carter Medlin
Carter Medlin

Reputation: 12475

try

if (Request.QueryString["ContactName"] != null)
   //My logic
else
    //My logic

Upvotes: 1

Related Questions