开发者

validating textbox with a button?

I have a button and a textbox, i want to check if the textbox validation is correct and passed correctly when i click on 开发者_开发问答the button. else the user should recieve a warning to check again what he had write in the textbox.


    public bool Validations()
    {
        if (string.IsNullOrEmpty(Textbox.Text))
        {
            MessageBox.Show(" Error ");
            return false;
        }
        else
        {
            // your code 
        }
    }

private void button1_Click(object sender, EventArgs e)

{

        if (!Validations())
            return;

    } 


Try using ErrorProvider. It may help.

private void button1_Click(object sender, EventArgs e)
{
    // check if something is wrong
    errorProvider1.SetError(textBox1,"Some Error!");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜