Reputation: 527
I have a dropdownlist and a textbox which has TextMode is Password. Whenever dropdownlist index changed the value of textbox disappear. Anyone have a solution to fix this? Tks so much.
Update
<asp:DropDownList ID="ddlstudentstatus" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlStudentstatus_SelectedIndexChanged">
</asp:DropDownList>
Upvotes: 0
Views: 2184
Reputation: 205
if you wanna have the text inside the textbox untouched when postingback, use the following in page_load:
if (IsPostBack)
{
if (!(String.IsNullOrEmpty(txtPassword.Text.Trim())))
{
txtPassword.Attributes["value"] = txtPassword.Text;
}
}
Upvotes: 3
Reputation: 3611
Changing autopostback value to false for the dropdown, would stop your SelectedIndexChanged event from firing. You can have a hiddenfield to store the value of the password textbox onblur, using javascript or jQuery.
$("#txtPassWord").blur(function()
$("#hdnPassWord").val($("#txtPassWord").val());
});
And then in the SelectedIndexChange event of the dropdown, you can assign value to txtPassWord from hdnPassWord.
txtPassWord.Text = hdnPassWord.Value;
If you are not posting back on SelectedIndexChanged, there's no meaning wiring up the event on server side. So be clear, which way to go.
Upvotes: 1
Reputation: 11308
Posting as an answer:
My guess is that the dropdown change is causing a postback. Passwords do not persist through postbacks.
Upvotes: 2