Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

keep-maintain password textbox value during postback asp.net

Jul 26, 2012
Introduction:

In this article I will explain how to keep or maintain text of password textbox during postback in asp.net
Description:

In previous posts I explained many articles relating to Asp.net, JQuery, and SQL etc. Now I will explain how to maintain text of password textbox during postbacks in asp.net. Generally if you observer password textbox it won’t maintain text if any postback happens like as shown below

If we want to maintain text of password textbox we need to write some code in pageload event for that first write the following code in your aspx page


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Maintain Password textbox data in postback</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><b>UserName:</b></td>
<td><asp:TextBox ID="txtUserName" runat="server"/></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><asp:TextBox ID="txtPwd" runat="server" TextMode="Password"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnSubmit" runat="server" Text="Submit" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
After completion of aspx page design write the following code in pageload event like as shown below

C# code


protected void Page_Load(object sender, EventArgs e)
{
string pwd = txtPwd.Text;
txtPwd.Attributes.Add("value", pwd);
}
VB.NET Code


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim pwd As String = txtPwd.Text
txtPwd.Attributes.Add("value", pwd)
End Sub
Demo


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

Anonymous said...

Just remember that, in that way, the value is visible in the page cource.

test4web said...

Thank You

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.