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
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
Demo
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
|
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. |
|||
|
|||
2 comments :
Just remember that, in that way, the value is visible in the page cource.
but for me password field is showing empty ....and trying to bind password from cookies and store that in a html textbox
Note: Only a member of this blog may post a comment.