Click here to Skip to main content
15,867,937 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
I am making two textbox for password field. One for password and second for re enter password.
I have written code in text change event. That
textbox1.text != textbox2.text
but it checks when everytime i change text. I want event which will only execute the code. After user have written the full password. Textchange event does it but it executes after every single character. I want to execute the code afte password have been totally typed.
Posted
Comments
__John_ 6-Nov-12 11:11am    
You have no way of knowing when they have finished typing.
You would have to do it when they press the button "Log in" or something similar.
Perić Željko 6-Nov-12 11:41am    
Not true !
Look at solution No. 5
Sergey Alexandrovich Kryukov 6-Nov-12 18:51pm    
In principle you are right, but your approach is not the same, it decreases the safety in case of short password. How much less safe -- is a philosophical question...
You did not disprove what __John_ says -- you still have no way of knowing if a used finished typing. In your approach, the user never "finishes typing", which is not the same. So, __John_ statement is still correct, and therefore your "Not true!" is not true.
--SA
Perić Željko 7-Nov-12 5:39am    
My first attempt to answer :
'In principle you are right,' ?! ( too much philosophical... )
Perhaps you could clarify what would be 'the end of typing', in general sense.
Or even more to define 'typing'.
Safety was not the issue in the question.
'If we could not find out did we ended typing or not oo

My second attempt
My answer (comment) was too short or insufficiently substantiated,
but has continued in a Solution No.5 as written.
I had error in comment. I have not sufficiently explained my comment.

My third attempt
If we do not know when the user have ended simple operation as typing in some text in text box
whell I surrender
'what does this means bro.
can you explain plz
i am a beginer'

You win I loose

hope you would not be angry afther this

cheers

I apologise too all readers of this comment for syntax errors in text.
Sergey Alexandrovich Kryukov 7-Nov-12 12:38pm    
Too much of what... you either want do discuss things with me or not. Let me be more precise: you told not true about comment by __John_, but you basically understand the nature of the problem. What you don't understand is simple logic. This is you who need to clarify what is "end of typing", because both __John_ and I already stated that such thing does not exist. I got your solution, it makes some sense (even though I would never recommend using it), but you should think thoroughly before blaming others for lie.
--SA

Use the Validating event of other TextBox, here, the code is only executed when the user has finished entering the password.
 
Share this answer
 
Comments
shaikh-adil 6-Nov-12 13:28pm    
+5thanks
Akinmade Bond 7-Nov-12 5:45am    
Has your question been answered? Please mark the answer that worked for you as solution.
you can use another method but no textChange for check two password
for example you can make under method and in button_click call it;
C#
 public  void CheckTwoPassword(string textbox1,string  textbox2)
{
 if(textbox1==textbox2)
  {
    //do some work 
  }
}


and your button click

public void Button_Click(sender s,object o)
{
 CheckTwoPassword(textbox1.text,textbox2.text);
}
 
Share this answer
 
Comments
shaikh-adil 6-Nov-12 13:28pm    
thanks bro
Hi,
You can compare passwords in "Leave" or "LostFocus" event of the second textbox
 
Share this answer
 
Comments
shaikh-adil 6-Nov-12 13:29pm    
yup.
thanks bro
To find out if user has ended entering password or not,
You can use different event handlers for Text Box control.

First is when user presses and releases a key,
when we check if user have pressed key 'Enter' as end of entered password.

Second is if user use mouse to change focus of current control,
select something else on form and ends input in current active Text Box.

In every event handler we have CheckPassword() call for sub
that process entered password (text) in Text Box.

Look at the code :

C#
void TextBox1KeyPress(object sender, KeyPressEventArgs e)
{
    // Implement TextBox1KeyPress

    //
    // this event occurs when control has focus and
    // the user presses and releases a key
    //

    if(e.KeyChar == (char) Keys.Enter)
    {
        CheckPassword();
    }
}

void TextBox1Leave(object sender, EventArgs e)
{
    // Implement TextBox1Leave

    //
    // this event occurs when control loses focus or
    // is no longer active control on the active form
    // ' user has clicked somewhere out of contol '
    //

    CheckPassword();

}


There are many more ways to handle this type of problem.
Try different event handlers : Text Box Events[^]

All the best,
Perić Željko
 
Share this answer
 
v4
Comments
shaikh-adil 6-Nov-12 13:23pm    
awsome ans. thanks bro
: )
+5
shaikh-adil 6-Nov-12 13:26pm    
if(e.KeyChar == (char) Keys.Enter)
{
CheckPassword();
}
what does this means bro.
can you explain plz
i am a beginer
Perić Željko 6-Nov-12 14:34pm    
If pressed key on keyboard is 'enter' than we assume that user has finished entering password into text box. If that is the case call CheckPassword() sub for checkout if password is the same in both text boxes.

void CheckPassword()
{
if (textbox1.text != textbox2.text)
{
do something...

}
}

EventHandlers must be coded for both text boxes if You want that your code works correct.
You may set same code for both text boxes.

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