Solved

Losing data in a password textbox on postback

Posted on 2010-09-22
5
2,059 Views
Last Modified: 2012-05-10
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">
  <ContentTemplate>
 <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"
                                                        AutoPostBack="true">
                                                    </asp:DropDownList>
   </ContentTemplate>
   </asp:UpdatePanel>
</ajaxToolkit:TabPanel>
0
Comment
Question by:vivekpv10
5 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 250 total points
ID: 33741481
0
 
LVL 14

Expert Comment

by:robasta
ID: 33741710
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...
0
 
LVL 5

Author Comment

by:vivekpv10
ID: 33742034
anyone know how it can be implemented using javascript??pls post that code also
0
 
LVL 3

Assisted Solution

by:revaluser
revaluser earned 250 total points
ID: 33742225
which ever the action is causing the postback action place this code

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

Over there

like

protected void Button1_Click(object sender, EventArgs e)
    {
        string strPasswordValue = TextBox1.Text.Trim();
        TextBox1.Attributes.Add("Value", strPasswordValue);
    }
0
 
LVL 5

Author Closing Comment

by:vivekpv10
ID: 33742353
awesome ansers..its working
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question