By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,742 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,742 IT Pros & Developers. It's quick & easy.

Password field is cleared after postback

P: n/a
Hello,

I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a postback,
in order to fill the second dropdown according to the value selected in the
first dropdown.
The problem is that the password field which has been filled up before is
cleared after postback.
I know this is for security, but is there a way to keep the password??

Thank you
Nov 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
dana lees wrote:
Hello,

I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a
postback, in order to fill the second dropdown according to the value
selected in the first dropdown.
The problem is that the password field which has been filled up before is
cleared after postback.
I know this is for security, but is there a way to keep the password??

Thank you


Yes, you can add a "value" attribute to the password textbox on postback:

txtPassword.Attributes.Add("value", txtPassword.Text)

Ben
Nov 23 '05 #2

P: n/a
I have tried that and it didn't work. The field stayed empty...

"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
dana lees wrote:
Hello,

I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a
postback, in order to fill the second dropdown according to the value
selected in the first dropdown.
The problem is that the password field which has been filled up before is cleared after postback.
I know this is for security, but is there a way to keep the password??

Thank you


Yes, you can add a "value" attribute to the password textbox on postback:

txtPassword.Attributes.Add("value", txtPassword.Text)

Ben

Nov 23 '05 #3

P: n/a
dana lees wrote:
I have tried that and it didn't work. The field stayed empty...


Hmm... not sure why that doesn't work. Are you using .NET v2.0? I've done
it in v1.1 without any problems.

Another option is to manually set the value of the password field via
JavaScript. There are several ways to do this.

One way is to create a hidden input field. On postback, put the password in
the hidden input field (i.e. txtHiddenPwd.Value = txtPwd.Text). Then with a
startup script or via the body tag's onload attribute, set the value of the
password textbox to the value of the hidden input field.

Ben
Nov 23 '05 #4

P: n/a
I am using version 1.1.
On debug, I see that i do have the value of the password after postback, i
just can't set the textbox with that value.

I have tried also javascript:

document.all.txtPassword.InnerText = "some text";

and this doesn't work as well...

I don't need to use a hidden textbox becuase i do have the value after
postback, i just can't set the textbox's value to that value...

"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:u2**************@tk2msftngp13.phx.gbl...
dana lees wrote:
I have tried that and it didn't work. The field stayed empty...
Hmm... not sure why that doesn't work. Are you using .NET v2.0? I've

done it in v1.1 without any problems.

Another option is to manually set the value of the password field via
JavaScript. There are several ways to do this.

One way is to create a hidden input field. On postback, put the password in the hidden input field (i.e. txtHiddenPwd.Value = txtPwd.Text). Then with a startup script or via the body tag's onload attribute, set the value of the password textbox to the value of the hidden input field.

Ben

Nov 23 '05 #5

P: n/a
dana lees wrote:
I am using version 1.1.
On debug, I see that i do have the value of the password after postback, i
just can't set the textbox with that value.

I have tried also javascript:

document.all.txtPassword.InnerText = "some text";

and this doesn't work as well...

I don't need to use a hidden textbox becuase i do have the value after
postback, i just can't set the textbox's value to that value...


Server-side you can't set the textbox's value to the password. However,
with JavaScript (client-side) you should be able to set the value of the
textbox with or without a hidden input field. Without a hidden input field,
you could simply add a runat="server" attribute to the <body> tag, then on
the server-side during a postback, you can add an "onload" attribute to the
body tag specifying the password value. Like this:

===== HTML =====
<body id="myBody" runat="server">

===== Code-Behind =====
myBody.Attributes.Add("onload", _
"document.getElementById('txtPassword').value = '" & _
txtPassword.Text & "'")

(the C# syntax should be similar)

Also, in the code-behind, if Visual Studio doesn't recognize the "myBody"
control (which happens sometimes), you'll probably have to manually add the
control declaration to the code-behind:

Dim myBody As HtmlControls.HtmlGenericControl

.... or instead of adding an "onload" attribute to the body tag, you could
use the RegisterStartupScript method to set the password textbox value.

Ben
Nov 23 '05 #6

P: n/a
dana lees wrote:
I have tried also javascript:

document.all.txtPassword.InnerText = "some text";

and this doesn't work as well...


By the way, what do you mean that it "doesn't work as well"? How about:

document.getElementById('txtPassword').value = "some text";

Ben
Nov 23 '05 #7

P: n/a
It worked, when using

document.getElementById('txtPassword').value = "some text";

Thank you very much :-)

"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
dana lees wrote:
I have tried also javascript:

document.all.txtPassword.InnerText = "some text";

and this doesn't work as well...


By the way, what do you mean that it "doesn't work as well"? How about:

document.getElementById('txtPassword').value = "some text";

Ben

Nov 23 '05 #8

P: n/a
Dana,

As Ben suggested you can use assword.Attributes.Add("value",
txtPassword.Text) to set the password .But instead of txtPassword.Text you
should retrieve password text using
txtPassword.Attributes["value"].ToString().

"dana lees" wrote:
I have tried that and it didn't work. The field stayed empty...

"Ben Amada" <be*@REpoMOweVErpick.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
dana lees wrote:
Hello,

I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a
postback, in order to fill the second dropdown according to the value
selected in the first dropdown.
The problem is that the password field which has been filled up before is cleared after postback.
I know this is for security, but is there a way to keep the password??

Thank you


Yes, you can add a "value" attribute to the password textbox on postback:

txtPassword.Attributes.Add("value", txtPassword.Text)

Ben


Nov 23 '05 #9

P: n/a
Check out:
http://groups.google.com/group/micro...e23fa30643fa4e

and
http://groups.google.com/group/micro...9f3be06c4f0396

(watch for link brakage). Basically, you need to reset the value manually
via Password.Attributes.Add("value", Password.Text) or something

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"dana lees" <da***@idc.ac.il> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello,

I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a
postback,
in order to fill the second dropdown according to the value selected in
the
first dropdown.
The problem is that the password field which has been filled up before is
cleared after postback.
I know this is for security, but is there a way to keep the password??

Thank you

Nov 23 '05 #10

P: n/a
Humm..I don't know why, but I thought this thread hadn't been answered
yet...*blush*

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%2***************@TK2MSFTNGP15.phx.gbl...
Check out:
http://groups.google.com/group/micro...e23fa30643fa4e

and
http://groups.google.com/group/micro...9f3be06c4f0396

(watch for link brakage). Basically, you need to reset the value manually
via Password.Attributes.Add("value", Password.Text) or something

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"dana lees" <da***@idc.ac.il> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hello,

I am developing a C# asp.net application.
I have a webform which contains 2 dropdowns and a textbox with
type="password".
On "SelectedIndexChanged" event of the first dropdown, there is a
postback,
in order to fill the second dropdown according to the value selected in
the
first dropdown.
The problem is that the password field which has been filled up before is
cleared after postback.
I know this is for security, but is there a way to keep the password??

Thank you


Nov 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.