Monday, July 25, 2011

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

18 comments:

  1. useful very much to me...

    ReplyDelete
  2. PostBack is the name given to the process of submitting an ASP.NET page to the server for processing .

    ReplyDelete
  3. A simple example to illustrate the usage of PostBack is a login page. After the user has typed his username and password, he clicks on the ‘Login’ button. Upon the click, the page is sent to the server to check against the database/XML file to check if the user with supplied details is an authenticated user.

    ReplyDelete
  4. password must be kept secret....

    ReplyDelete
  5. Postback in an event that is triggered when a action is performed by a contol on a asp.net page.

    ReplyDelete
  6. Just do one thing after write down your Password do one thing take one hidden field in your form and Insert value on Postback (when you select combo box) after combo box coding executed again insert value from hidden value to Password field.

    ReplyDelete
  7. Very informative. Hope this technique will be used in an ethical way by developers and not misused in anyways.

    ReplyDelete
  8. IPostBackEventHandler serves to capture a client-side postback event (a click)

    ReplyDelete
  9. Works - but now you have your password in the HTML source IN CLEAR TEXT ! Anyone can spy on that - not a very smart solution in my opinion .....

    ReplyDelete
  10. I'm truly enjoying the design and layout of your blog.
    It's a very easy on the eyes which makes it much more pleasant for me to come here
    and visit more often. Did you hire out a developer to create your theme?
    Outstanding work!

    my page - clash of clans hack

    ReplyDelete
  11. constantly i used to read smaller content which as well clear
    their motive, and that is also happening with this post which
    I am reading at this time.

    Feel free to surf to my web blog; real racing 3 cheater (1rem.com)

    ReplyDelete
  12. Thanks all for your comments folks.Password must keep secret but the person who enter the password in textbox will only able to see through right click view source option.So no need to worry

    ReplyDelete
  13. I have read your blog its very attractive and impressive. I like it your blog.

    Dot Net Training in Chennai Dot Net Training in Chennai .Net Online Training .Net Online Training Dot Net Training in Chennai Dot Net Training in Chennai


    Dot Net Online Training Dot Net Online Training LINQ Online Training LINQ Online Training ASP.NET Online Training ASP.NET Online Training

    ReplyDelete
  14. Nice explanation with snapshots, keep it up for more Dotnet online training

    ReplyDelete
  15. The CCNA assertion shows an expertise in frameworks organization and consistent topologies. It exhibits that we can present, organize, and work LAN, WAN, and dial access organizations, including yet not compelled to the use of these traditions: IP, IGRP, Serial, Frame Relay, IP RIP, VLANs, RIP, Ethernet, and Access Lists.
    Regards,
    ccna Training in Chennai | ccna course in Chennai | ccna Training institute in Chennai

    ReplyDelete
  16. his article is very nice and easy to understand, it was a very weighty once thanks a lot admin can hopefully be improved in the future and pardon me permission to share the article here : Cara menyembuhkan gagal jantung

    ReplyDelete

Followers