467,926 Members | 2,082 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,926 developers. It's quick & easy.

Several question : postback, focus

Hello,

I have 2 questions :

1. On an ASP.NET page I have several controls (5 TextBox, 1 Dropdown and 1
button)
Only the dropdown is AutoPostBack = true, the TextBox are SingleLine

When I execute the page, I fill in the textbox, I change the dropdown
selection, the page is reloaded no problem I see the textbox still fill in.

Now I change TextMode to Password for 2 TextBox. I execute the page, I fill
in, I change the Dropdown selection when the page is reloaded the TextBox
with TextMode to password are empty.

Is it normal ? How can I solve that ?

2. How can I give the focus to the first textbox of the page ? For the
moment I use a javascript in the bottom of the page but that's not work very
well mainly when I use the dropdown the focus is on the first control.

Thanks,

C.
Nov 18 '05 #1
  • viewed: 3602
Share:
4 Replies
When a textbox's textmode property is set to password the viewstate for the textbox does not work. The reason for this is that if the user views the source of the HTML rendered after the postback, he/she will see the password in plain text. This defeats the purpose of having a masked password textbox. One way to circumvent the problem is to keep the password in memory on the server, or to use other means other than viewstate.

A technique that I've seen which executes javascript after a page loads, so that it can reference the controls, is to put a literal control at the very bottom of the page, and fill it with the javascript code which sets the focus. Another way would be to put it in the body onload event, which executes only when the controls on the page are loaded.

hope this helps,
John
"Christian Ista" wrote:
Hello,

I have 2 questions :

1. On an ASP.NET page I have several controls (5 TextBox, 1 Dropdown and 1
button)
Only the dropdown is AutoPostBack = true, the TextBox are SingleLine

When I execute the page, I fill in the textbox, I change the dropdown
selection, the page is reloaded no problem I see the textbox still fill in.

Now I change TextMode to Password for 2 TextBox. I execute the page, I fill
in, I change the Dropdown selection when the page is reloaded the TextBox
with TextMode to password are empty.

Is it normal ? How can I solve that ?

2. How can I give the focus to the first textbox of the page ? For the
moment I use a javascript in the bottom of the page but that's not work very
well mainly when I use the dropdown the focus is on the first control.

Thanks,

C.

Nov 18 '05 #2
>When a textbox's textmode property is set to password the viewstate for the
textbox does not work. The >reason for this is that if the user views the
source of the HTML rendered after the postback, he/she will see
the password in plain text. This defeats the purpose of having a masked

password textbox. One way to >circumvent the problem is to keep the password
in memory on the server, or to use other means other than >viewstate.

What do you say by "memory on the server" ? You talk about a Session
variable ?

I tried this kind of solution, I wanted fill in the textbox in Page_Load
event but at this time the control is not neated yet and I receive an error.
Is there an another event where I can do that ?

Thanks,
Nov 18 '05 #3
Question 1:
For security reasons, it is by design that textbox fields with
type="password" are not cached by the browser, and ASP.NET does not
preserve the value of a password textbox in the viewstate. This is a
normal behavior.

You can ask the user to enter the password again, or maybe put the
password textbox on another page, and only bring the user to the
password page when the user has entered all the informations
correctly.

Question 2:
I don't fully understand this question. Could you provide more
details?

I had the following at the end of the page, and it works fine.
<script language="javascript">
document.getElementById('txtInput').focus();
</script>

One thing I want to point out is that the asp.net dropdownlist only
autopostback if the user has selected a different item. If you only
have one item in the dropdownlist, it'll never postback to the page.

Tommy,

"Christian Ista" <ml@cista.be> wrote in message news:<#P**************@tk2msftngp13.phx.gbl>...
Hello,

I have 2 questions :

1. On an ASP.NET page I have several controls (5 TextBox, 1 Dropdown and 1
button)
Only the dropdown is AutoPostBack = true, the TextBox are SingleLine

When I execute the page, I fill in the textbox, I change the dropdown
selection, the page is reloaded no problem I see the textbox still fill in.

Now I change TextMode to Password for 2 TextBox. I execute the page, I fill
in, I change the Dropdown selection when the page is reloaded the TextBox
with TextMode to password are empty.

Is it normal ? How can I solve that ?

2. How can I give the focus to the first textbox of the page ? For the
moment I use a javascript in the bottom of the page but that's not work very
well mainly when I use the dropdown the focus is on the first control.

Thanks,

C.

Nov 18 '05 #4
Yes Session object is one, but not so secure as it can be viable to cross site scripting attacks since it uses cookies. If you store Session state in SQL Server though it would work great. Or you can store the info in a variable declared globally to the page.

For your second question, I did not mean the Page_Load, but the <body onload=>. To do this, you will have to go directly on the HTML page and put in the code, you cannot do this is codebehind. If you are using Visual Studio .NET you have to switch to the HTML view, find the body tag and enter the javascript that puts focus to the textbox there. This event occurs when all the controls are loaded into memory on the client-side. If you put the code at the end of the page, it will work most of the time, but you are not guaranteed that the textbox where you want to put focus to will be loaded. This is the only surefire technique.

hope this helps,
John

"Christian Ista" wrote:
When a textbox's textmode property is set to password the viewstate for the

textbox does not work. The >reason for this is that if the user views the
source of the HTML rendered after the postback, he/she will see
the password in plain text. This defeats the purpose of having a masked

password textbox. One way to >circumvent the problem is to keep the password
in memory on the server, or to use other means other than >viewstate.

What do you say by "memory on the server" ? You talk about a Session
variable ?

I tried this kind of solution, I wanted fill in the textbox in Page_Load
event but at this time the control is not neated yet and I receive an error.
Is there an another event where I can do that ?

Thanks,

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Marco Liedekerken | last post: by
1 post views Thread by John Wilson | last post: by
4 posts views Thread by Dusty Hackney | last post: by
4 posts views Thread by kpg | last post: by
26 posts views Thread by JJ | last post: by
2 posts views Thread by Rey | last post: by
24 posts views Thread by erickme | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.