Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
in my web form one checkbox and one textbox

this is my code
C#
protected void txtpwd_TextChanged(object sender, EventArgs e)
       {
           if (txtpwd.Text == "123")
           {
               chckbox.Checked = true;
           }
           else
           {
               chckbox.Checked = false;
           }
       }



it's working but
i wanna show result like when ever i typing the password it will be changed


but it's working
when ever i leave the texbox it will checked

can u please tell me

thankxxx
Posted
Updated 2-Apr-15 1:18am
v3
Comments
Parazival 2-Apr-15 7:27am    
Please give me a correct solution

If you want to do that while the user is typing, you can't do it in C# - as MSDN says:
"The TextChanged event is raised when the content of the text box changes between posts to the server." https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged(v=vs.110).aspx[^]

That doesn't mean it happens on each character press by the user!
If you want this to work as the user types, you need to do it in JavaScript: http://www.w3schools.com/jsref/event_onchange.asp[^]
 
Share this answer
 
You will need a method that will check the validity of the password.
For e.g. in code below IsValidPasxword() will check if password is valid.

C#
protected void txtpwd_TextChanged(object sender, EventArgs e)
{
    if (txtpwd.Text == IsValidPasxword())
    {
        chckbox.Checked = true;
    }
    else
    {
        chckbox.Checked = false;
    }
}
private bool IsValidPasxword()
{
     //Check conditions for strong password
}
 
Share this answer
 
You want to detect every keystroke that a use enters, better use a JavaScript function which will only occur on the browser, without having to make a round trip to the server. Check this out: http://www.w3schools.com/jsref/event_onkeyup.asp[^]
 
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