Autopostback Problems

Hello All

I'm using AsP.Net 2003.  I have a textbox with Password Textmode.  I also have a combobox that changes the items in another combobox based on the selection.

My problem is the Autopostback of the combobox clears the password textbox.

How do I keep the value in the textbox when the user selects from the combobox?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Password feild values are not retained in the viewstate so they are not maintained accross postback, otherwise they would be visible in the source.

There is a solution here->

But just rememeber you are then making it visible in the source and disregarding the ****'s. If this security is not critical to you then maybe you still want to do it. Personally you may as well just use a normal textbox intead as you are bypassing the security the ***** offer.

Otherwise try to do all the processing on the page first and then set the password after.
Or you could try this solution, not one I have tried.

In page_load, get the value from the textbox and assign it back using the attributes.value, i.e.

TextboxID.Attributes.Add("value", TextboxID.Text);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
When a page is postbacked assword will not store, I would prefer you to use UpdatePanel then the value present in password will not clear

do not keep password textbox in updatepanel
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

example to use Update panel

 <asp:UpdatePanel ID="upnlUserName" runat="server">
                                <asp:TextBox ID="txtUserName" runat="server" Width="200" AutoPostBack="True" CausesValidation="True"

if there are any other controls which depend on combobox provide an another updatepanel to other controls

 <asp:UpdatePanel ID="upnlFirstName" runat="server">
                                <asp:TextBox ID="txtFirstName" runat="server" Width="200"  CausesValidation="True"

Here is the other method to store passoword

aspx code

<asp:TextBox ID="txtPassword" runat="server" TextMode="password"></asp:TextBox>
        <asp:DropDownList ID="ddlCombo" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlCombo_SelectedIndexChanged" >
                                <asp:ListItem Value="Value1" Text="value1"></asp:ListItem>
                                <asp:ListItem Value="Value2" Text="value2"></asp:ListItem>
                                <asp:ListItem Value="Value3" Text="value3"></asp:ListItem>
                                <asp:ListItem Value="Value4" Text="value4"></asp:ListItem>

.cs file code

 protected void ddlCombo_SelectedIndexChanged(object sender, EventArgs e)
        string strPassword = txtPassword.Text;
        txtPassword.Attributes.Add("value", strPassword);
RichWAuthor Commented:
Si_Hibbard, your solution worked, but the site is not showing me a link to accept your answer.  I've never seen this before.  I don't know what to do.
RichWAuthor Commented:
Once I posted the comment the buttons appeared to accept the answer.  Thank you for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.