Reputation: 4721
While submitting a form, I am not selecting any value from the dropdownlist and I am checking condition as
if (Request.Form["CmbNextUser"] != Session["UserId"].ToString() || Request.Form["CmbNextUser"] != null || Request.Form["CmbNextUser"] != "")
{
TransferMail();
}
So, while debugging my value comes as like below.
The value is coming blank but still it is going in the IF condition
Upvotes: 0
Views: 68
Reputation: 6417
Your IF conditions have logical ORs between them. This means if any one of them are met, the whole thing will execute. Did you mean to use && (and) instead of || (or).
Upvotes: 0
Reputation: 12309
Condition one is causing for this since you are comparing value
Request.Form["CmbNextUser"] != Session["UserId"].ToString()
i.e "" != Session["UserId"].ToString()
which is evaluated as ture
thats why it it executing if block.
Change code like this
if (!String.IsNullOrEmpty(Request.Form["CmbNextUser"]) || Request.Form["CmbNextUser"] != Session["UserId"].ToString() )
{
TransferMail();
}
Upvotes: 1