Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends.

i have problem in using goto statement in the inside and outside of an event;

i have a button in my form. in the click event of this form i have a messagebox with yes and no

buttons. i want if user click yes, he can enter some information in forms textboxes and again

click the button. i used goto statement before click event but it does not work. what i must do?

please help.
Posted
Comments
ArunRajendra 25-Mar-14 5:59am    
Post you requirement. Goto is not a good practice.
_Starbug_ 25-Mar-14 6:03am    
what requirements? you mean code?

1 solution

First off, don't use Goto - in fact forget it exists for a couple of years, by which time you should have a better idea of when it is appropriate to use it.
Instead, try something like this:
C#
private void button1_Click(object sender, EventArgs e)
    {
    if (MessageBox.Show("Enter more data?", "Data Saved", MessageBoxButtons.YesNo) == DialogResult.No)
        {
        Close();
        }
    }
Which closes your form if the user doesn't want to enter more data.
 
Share this answer
 
Comments
_Starbug_ 25-Mar-14 6:09am    
that is correct, but when dialogresult=Yes i want to user can add some information in textboxes and he can again click the button and this cycle can continue.
OriginalGriff 25-Mar-14 6:25am    
That's the whole idea: until the form is closed, your use can continue to add info. When he says "No, I'd finished" the form closes and he can't enter data any more.

This isn't like console programming: events happen at "random" intervals and your code responds to them - you don't force the user to do anything in any particular order.

So the user enters his data, presses the "Save" button and you save it and ask if he wants to enter more. You don't try to use "goto" to jump outside an event handler! :laugh:
_Starbug_ 25-Mar-14 6:40am    
i can write code for the time that user says "i do not want to enter any information" but i do not know what to do when he says "i want to enter more information".
if i use goto statement what i must do? because i do not have more time to edit my program structure.
OriginalGriff 25-Mar-14 6:59am    
Do not use goto.

If you are using buttons, and forms, then you react to events, you do not control what happens where.
I can't tell you what to do in detail, without seeing your code - but by the sound of it you are trying to write a console application in windows forms: and that won't work without radical changes!
Aarti Meswania 25-Mar-14 6:12am    
5+! :)

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