C# .NET - Button validation - Asked By shaheen parveen on 16-May-10 01:01 PM

Hi.......
i want to perform validation on button...how should i do it....
problem is:

i have one button...after clicking button some value should displayed in the textBox...
what i want is user should to move to next control on form only after clicking the button.....
similar to that of textBox Validation...

can any one help me....

thanks.

Web Star replied to shaheen parveen on 16-May-10 01:46 PM
When u are using validation control in asp.net that by default perform validation on button click.

if u want to use validation in javascript than u add that validation function on button's click event as follows

btnSubmit.Attribute.Add("onClick", "javascript:valfunction();");

and u can put your desired validation code in that javascript function
Anoop S replied to shaheen parveen on 16-May-10 02:07 PM
you can simply check textbox1.Text=="" in next control and if that true then you can display message that need to click the button
Goniey N (Mr. G) replied to shaheen parveen on 16-May-10 11:05 PM
You Can Check That If In Textbox Some Value  Or Not.


Using RequiredFieldValidator You Can Achieve This On The Textbox.

Take RequiredFieldValidator From The Validation Control & Set It's Property.

ControlToValidate : In This Property You Have To Set Your Textbox For Which You Want Validation. When Your Click On This It Will Display All Control Of Your From From That Select Your Textbox. Suppose Here "txtValue".

Error Message : Using This Property You Can Set Appropriate Message To The User.

Now If In The Textbox No Value Then It Will Give Error Message To The User.


Using This You Can Solve Your Problem...
Sagar P replied to shaheen parveen on 17-May-10 04:14 AM
ON your button click you can check the value of textbox and according to that you can move to next textbox like;

if(textBox1.Text=="")
{
    textBox1.Focus();
    MessageBox.Show("Please enter value in TextBox1");
    return;
}
else
{
    //here you can move cursor to next textbox like;
    textBox2.Focus();
}