Click here to Skip to main content
16,018,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello! First Sorry for my bad English. I have three classes and I need to save my var userId in my form . First Class is:

C#
private void buttonOk_Click(object sender, EventArgs e)
       {


           UserEntity user = new UserEntity(textBoxUsername.Text,textBoxPassword.Text);
           if (user.getUser()) {


               MainPanel mp = new MainPanel();
               mp.User = user;
               mp.Show();

           }


When the button is clicked we go to Second class:


C#
private void ProfitPanelButton_Click(object sender, EventArgs e)
       {

           UserEntity user = new UserEntity();
           if (user.getUser())
           {

               ProfitPanel pp = new ProfitPanel();
               pp.User = user;
               pp.Show();

           }
           else
           {
               MessageBox.Show("ERROR");
           }


       }


When We clicked ProfitPanelButton go to profit and insert Profit into DB .


I don't have any problem with going from 1st button directly to 3rd with code :



C#
private void buttonOk_Click(object sender, EventArgs e)
    {


        UserEntity user = new UserEntity(textBoxUsername.Text,textBoxPassword.Text);
        if (user.getUser()) {

            ProfitPanel pp = new ProfitPanel();
            pp.User = user;
            pp.Show();


     }

    }


Can you help me to fix this problem or give me some idea. Thanks.
Posted
Updated 30-Jul-12 10:14am
v2
Comments
El_Codero 30-Jul-12 16:14pm    
Edit: Code tags added.
[no name] 30-Jul-12 16:20pm    
Was there a question somewhere in this? "fix" what problem?
Sergey Alexandrovich Kryukov 30-Jul-12 17:19pm    
No a question, the problem is not clear, and not because of poor English (which is fine).
--SA
kespinko 1-Aug-12 15:58pm    
only should remove If statement in second and third button.

It's my first post thats why sorry for unclear question :(

1 solution

There's no clear question here, but if you call Show, which creates a modeless dialog, if you do it with a local variable, you lose your reference to that object right away, which stops you from interacting with it. Make it a member variable, then edit your question so you ask something clearly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900