Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai all,

When i use backspace in passsword char textbox whole page is getting refreshed.

I want to avoid page refreeshing.

Please give some ideas........
Posted

The backspace key is a default browser behaviour which is the same as clicking the back button.

Although that behaviour is overwritten when a textbox has focus. Are you sure the textbox has focus when you're hitting the backspace key?

If the textbox does has focus, then there will be a scripted behaviour change using the onkeypress event within your page.
 
Share this answer
 
Comments
AshishChaudha 22-Oct-12 8:09am    
Agreed
Malarpalanisamy 22-Oct-12 8:49am    
i didnt script for onkeypress event
Are you sure you didnt have apply any event on Password Texbox. Please confirm that.

Thanks
 
Share this answer
 
You can achive this using java script
<asp:TextBox ID="TextBox1" runat="server" onKeyDown="preventBackspace();
"></asp:TextBox>

and the script looks like this:
XML
<script type="text/javascript">
            function preventBackspace(e) {
                var evt = e || window.event;
                if (evt) {
                    var keyCode = evt.charCode || evt.keyCode;
                    if (keyCode === 8) {
                        if (evt.preventDefault) {
                            evt.preventDefault();
                        }
                        else {
                            evt.returnValue = false;
                        }
                    }
                }
            }
        </script>
 
Share this answer
 
Comments
Malarpalanisamy 22-Oct-12 8:50am    
My problem is not to prevent backspace in my application sir,i need to allow backspace.prevent page refreshing when backspace is pressed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900