Shantanu Gupta
Shantanu Gupta

Reputation: 21188

Javascript onKeyPress event not working?

Why does this statement work with OnKeyPress event of Javascript in C#.

 txtPassword.Attributes.Add("OnKeyUp", "CheckPasswordStrength(\"" 
                + txtPassword.ClientID.ToString() + "\",\""+  lblMessage.ClientID.ToString() +"\")");

this code is working correctly, my problem is that i want to run keypress event not keyup event

Upvotes: 1

Views: 1986

Answers (3)

DoctorLouie
DoctorLouie

Reputation: 2674

Use on onKeyDown for Windows/MSIE.

Upvotes: 1

D. Patrick
D. Patrick

Reputation: 3022

Change "onkeyup" to "onkeypress?" Maybe I'm not understanding.

Upvotes: 0

Canavar
Canavar

Reputation: 48088

You should check the rendered output by viewing source of the page but I think your problem is about double quotes. Replace them with single quotes.

txtPassword.Attributes.Add("OnKeyUp", "CheckPasswordStrength('" 
            + txtPassword.ClientID.ToString() + "','"+  lblMessage.ClientID.ToString() 
+"')");

this will probably rendered as :

<input onkeyup="CheckPasswordStrength('clientIdhere', 'clientIdhere');" />

Upvotes: 1

Related Questions