TextMode : Password

  • Thread starter Thread starter Lubomir
  • Start date Start date
L

Lubomir

Hi,

I am using the textBox in mode "Password" to show '*" instead of entered
characters. when i read back the user input, the Text property contains an
empty string.

How can I get the text box value (entered string) if the TextBox is working
in a mode "password" ?

Thanks.
Lubomir
 
It is working fine - can you pass your code over?
Here is my code that works just fine

<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" runat="server"
TextMode="Password"></asp:TextBox>

</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim myPassword As String = TextBox1.Text
End Sub


myPassword gets the proper value.
 
The code is something like this:

<asp:view ID="FIRST">
....
<asp:TextBox ID="AAA" runat="server" TextMode="Password"></asp:TextBox>
....
</asp:view>

<asp:view ID="SECOND">
....
<asp:LinkButton ...OnClick="ClickHandler" Commandname="NextView">
aabcd</asp:LinkButton>
....
</asp:view>

public void ClickHandler(object sender, EventArgs e)
{
string test = AAA.Text; // will be empty string
}

The values for another textboxes from the view ID="FIRST" are correct. Only
AAA textbox value (password) is lost.

If I test the value for AAA while still being in the view FIRST, the textbox
AAA has a corect value (contains the entered password string).

/Lubomir
 
There is nothing special you need to do to retreive the text of a textbox in
password mode. Setting this mode simply masks the input in the UI. It does
nothing to the actual value stored in the object.

If you are not getting the value out, there must be another issue.

-Scott
 
I found out the reason why the password value is an empty string: the TextBox
in a mode = Password has restriction => its value (password) is not restored
after a postback.

/Lubomir
 
Back
Top