Introduction
In this post I will explain how to maintain the password textbox text after postback. My previous post SQL Query to find Nth Highest or Lowest salary of an employee table.
Explanation
In Asp.net the password textbox will not remain the value after a postback happen, because the viewstate value will disappear. So for retaining the value in textbox control we have again reassign the value in viewstate.
Design
Code behind
In code behind textbox pre render event we have to assign the textbox value.
Output
Note: By using the above code the password will show plain if view through page source code. My previous post SQL Query to find Nth Highest or Lowest salary of an employee table.
In this post I will explain how to maintain the password textbox text after postback. My previous post SQL Query to find Nth Highest or Lowest salary of an employee table.
Explanation
In Asp.net the password textbox will not remain the value after a postback happen, because the viewstate value will disappear. So for retaining the value in textbox control we have again reassign the value in viewstate.
Design
<asp:textbox onprerender="txtPassword_PreRender" id="txtPassword" text="abcd" maxlength="25" cssclass="TextBox" width="150px" runat="server" textmode="Password"></asp:textbox>
<asp:button onclick="btnSubmit_Click" id="btnSubmit" runat="server" text="Submit"/>
Code behind
In code behind textbox pre render event we have to assign the textbox value.
protected void txtPassword_PreRender(object sender, EventArgs e)
{
txtPassword.Attributes["value"] = txtPassword.Text;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
}
Output
Note: By using the above code the password will show plain if view through page source code. My previous post SQL Query to find Nth Highest or Lowest salary of an employee table.