ASP.net C3 IF condition ispostback

1.4k Views Asked by At

Can anyone explain to me what this conditions means, thanks in advance.

if (!String.IsNullOrEmpty(Request["code"]) && !Page.IsPostBack)
{
    code = Request["code"].ToString();
}
2

There are 2 best solutions below

3
On BEST ANSWER

The supplied Snippet will check for two conditions 1. !String.IsNullOrEmpty(Request["code"]) and 2. !Page.IsPostBack and Will execute the statement code = Request["code"].ToString(); only if both the conditions ware true.

More Details about the two conditions mentioned in the if():

1. String.IsNullOrEmpty(Request["code"]):

String.IsNullOrEmpty() Indicates whether the specified string is null or an Empty string. It will return true if the value parameter is null or an empty string (""); otherwise, false.

2. Page.IsPostBack:

Page.IsPostBack Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback. It will return true if the page is being loaded in response to a client postback; otherwise, false.

Note : In both the conditions ! symbol will negates the return value from the function. That means if Page.IsPostBack() returns true then !Page.IsPostBack() will convert it to false and wise versa.

Summary:

The code will check whether the query-string parameter "code" (Request["code"]) is null or empty, and check whether it is a postback event or not, only when the first condition is true(ie., Request["code"] have some value other than "").

0
On

if (ispostback is not true)means the page dose not load from the server control and (request["Code"] is not null) means it exist and (request["Code"] is not empty) means it's not equal ""