How to restrict the backspace control in textbox? [Resolved]

Posted by Sudheep.grandhe under C# on 11/11/2011 | Points: 10 | Views : 7374 | Status : [Member] | Replies : 2
Hi,

I am currently developing windows applications.for example i have two textboxes.i enter the data in textbox1 as wrong unfortunately my cursor was goto textbox2.if i understand the wrong entry in textbox1 and again i will go to textbox and erase the data and entered correctly.my intension is i wont allow this.one more thing i want to avoid backspace option in my textbox respectively.how can i do this.please do the needful.

Best,
Sudheep.



Responses

Posted by: Blessyjees on: 11/11/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Try this

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{
if (e.KeyChar == 8)
{
e.Handled = true;
}
}


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 11/15/2011 [Member] Starter | Points: 25

Up
0
Down
In html page call thE FUNCTION like this

<asp:TextBox ID="TextBox1" runat="server" TabIndex="1" Width="50px" onKeyPress="FocusNext(this)"></asp:TextBox>



in the head put this code to block keyboard button by their code

<script language ="javascript" type ="text/javascript" >
function FocusNext(cid)
{
if (e.KeyChar == 8)

{

e.Handled = true;

}

}
</script>


or this is in .cs page
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

{

if (e.KeyChar == 8)

{

e.Handled = true;

}

}

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response