IsPostBack which is more standard / performant

32 views Asked by At

i have came across many pre written asp.net web apps and many opensource asp.net web apps.

some where i had found

page_load()
{
    if(!IsPostBack)
    {

      //code logic
    }

}

where some other sites i had found

page_load()
{
    if(IsPostBack) return;
    //code logic

}

my question is which one of this is better code standard and which one of these is more performance.

1

There are 1 answers

0
momo On

There is no performance impact because the condition will be executed in both examples and the compiler may optimize the code anyway. It's just a matter of taste. The second one:

page_load()
{
    if(IsPostBack) return;
    //code logic

}

is known as a "Guard Clause". Read more at wiki.c2.com/?GuardClause.