• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2392
  • Last Modified:

Losing data in a password textbox on postback

I have a password textbox in my page.Also there is drwopdownlist in same form.my problem is when i changing an item in the drowdownlist,password textbox also get cleared.How can i solve this.The entire thing is inside a tab page.  
<ajaxToolkit:TabPanel ID="tpUserMgmt" runat="server" HeaderText="User Management">
<asp:UpdatePanel ID="Panel_UserProf" runat="server">
 <asp:TextBox ID="txt_Pwd" runat="server" MaxLength="15" TextMode="Password"  ValidationGroup="CreateUser" Width="130px">
<asp:DropDownList ID="dd_Dsgnt" runat="server" Width="130px" OnSelectedIndexChanged="dd_Dsgnt_SelectedIndexChanged"
2 Solutions
1.AutoPostBack="true" on a Dropdownlist will do a postback
2. TextMode="Password" on a Textbox will clear contents after a postback

There are different ways to solve this 'by design' scenario. The following are suggestions:

a) Save the password in session or in a hidden field and put it back after the postback(not sure about the security risks involved here).
b) Add the textbox below the dropdown, so that the user enters password after drop down has already done a postback
c) Take the textbox outside the updatepanel
d) place the password box on a seperate tab...
vivekpv10Author Commented:
anyone know how it can be implemented using javascript??pls post that code also
which ever the action is causing the postback action place this code

string strPasswordValue = TextBox1.Text.Trim();
TextBox1.Attributes.Add("Value", strPasswordValue);

Over there


protected void Button1_Click(object sender, EventArgs e)
        string strPasswordValue = TextBox1.Text.Trim();
        TextBox1.Attributes.Add("Value", strPasswordValue);
vivekpv10Author Commented:
awesome ansers..its working
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now