Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to maintain the password textbox text after postback

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

<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.



This post first appeared on Dotnet, please read the originial post: here

Share the post

How to maintain the password textbox text after postback

×

Subscribe to Dotnet

Get updates delivered right to your inbox!

Thank you for your subscription

×