But that defeats the purpose of IsPostBack, no? it becomes useless to
have it if other areas in the class gets executed on post back.

I do get what you mean though, looks like a session is what I will be
after.

Thanks.

On Apr 10, 7:05 pm, The_Fruitman <[email protected]> wrote:
> The reason is because of how ASP.NET handles page post backs.  If you
> were to store the emp in a session variable or a cookie then you could
> easily retrieve it even after a post back and additionally pass it
> between pages.
>
> What is most likely happening in the above code is the page begins its
> post back and calls the public partial class _default :
> System.Web.UI.Page
> Then it creates a new Employee emp which is then set to null.
> It then goes into the page_load function and checks to see if the page
> is a post back or not.
>
> On Apr 10, 11:57 am, Maya <[email protected]> wrote:
>
>
>
> > Hi guys, Is there a reason why emp object is becoming null when I
> > click the submit button??
>
> > It works fine when I first load the page, the object gets populated,
> > but when  btn_confirm_Click() gets executed the emp is null.
>
> > Thanks,
>
> > Maya.
>
> > public partial class _default : System.Web.UI.Page
> >     {
>
> >        Employee emp;
>
> >         protected void Page_Load(object sender, EventArgs e)
> >         {
> >             if (!Page.IsPostBack)
> >             {
>
> >                 emp = new Employee ().GetEmployee();
>
> >             }
> >         }
>
> >         protected void btn_confirm_Click(object sender, EventArgs e)
> >         {
>
> >                 emp.FirstName = "something";
> >                 emp.LastName = "something";
>
> >           }
> >     }

Reply via email to