views:

70

answers:

3

Hi All,

I want to create separate textbox for numbers and string using c# code. I should not use jquery or javascript. Can anyone pls help me.

Condition:

Numeric Textbox: It should not allow characters, special characters.
String Textbox: Should not allow numbers, Special characters.

A: 

I think you can use Masked C# TextBox Control

Sudantha
A: 

for numbers only

private void txtType1_KeyPress(object sender, KeyPressEventArgs e) { int isNumber = 0; e.Handled = !int.TryParse(e.KeyChar.ToString(), out isNumber); }

for text only

private void txtType1_KeyPress(object sender, KeyPressEventArgs e) { int Length=textbox1.Length; int Loop; for(Loop=1;Loop<=Length;Loop++) { char c=textbox1.subString(Loop,1); if(( c<'a' && c>'z') || (c<'A' && c>'Z')) { Messagebox.Show("Please Enter Only Alphabets"); e.Handle=true; } } }

william
you would be able to paste text into the number box
Jonathan
yea coz..i m monitoring keydown event
william
A: 

Have a look at the Validation Controls ; these include client-side (javascript) and server-side validation logic.

ChristopheD