Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a numeric keypad for touch screen using C# and ASP.NET, allowing an user to enter the pin number of size 4 for login.
When the user touches on a particular number, it should appear in a text box but as a *. For this, I have used hidden field that tracks number entered by user and in the text box a * is shown every time the user touches any number.
What I would like is that the cursor position is maintained and is moved according the entry.
Everything works fine but I need the cursor position to be maintained in it.

Here is code when 7 is pressed:
C#
protected void lnkNumberPadSeven_Click(object sender, EventArgs e)
  {
      string num = lnkNumberPadSeven.CommandArgument;
      if (txtPassword.Text.Length <= 3)
      {
          txtPassword.Text = string.Concat(Server.HtmlEncode(txtPassword.Text.ToString()), "*");
          hdnPassword.Value = string.Concat(hdnPassword.Value, num);
      }
  }

Can anyone help.. ??
Posted
Updated 25-Jan-14 23:04pm
v3
Comments
JoCodes 27-Jan-14 0:03am    
You can use TextMode="Password" for the textbox .
Codes DeCodes 27-Jan-14 3:30am    
thanks for the code jocodes.. guess it works only when user types pin from keyboard.. in my case,, user selected the number and the number is concated... so in reference to above code for lnkNumberPadSeven_Click, as 7 is pressed on screen, 7 is shown insted of *..

1 solution

Easiest way? Don't replace it yourself! If you set the TextBox.UseSystemPassword property to true, it will do it for you. Or, if you must use "*" characters, then leave UseSystemPassword at false, as set TextBox.Password Char to '*' and it will use that instead.

If you really, really, must do it yourself, then I think what you really want to do is just add the line:
C#
txtPassword.Focus();
to your method above.
 
Share this answer
 
Comments
Codes DeCodes 26-Jan-14 6:05am    
i could not get u ... i could not access TextBox.UseSystemPassword property.. where is it located ???
OriginalGriff 26-Jan-14 6:27am    
Look in the properties pane for your textbox control...

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