We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Input box

Thread ID:





5000 Jun 13,2003 04:34 AM UTC Jun 25,2003 12:12 PM UTC WinForms 3
Tags: FAQ
Yogendra Patil
Asked On June 13, 2003 04:34 AM UTC

I am using an inputbox to allow the user to input some value. If the user doesnt enter anything and clicks OK Button, i want to display a message box asking for input and show the same input box again. If the user doesnt enter anything and clicks cancel button, then no messagebox to be displayed. How do i get through this?

Ramesh Praveen [Syncfusion]
Replied On June 25, 2003 11:44 AM UTC

Listen to the OK button's click event, and if a valid value is not in the textbox, fire a message box and then set the focus back to the textbox; otherwise close the dialog by setting it's DialogResult value approriately. Note that the DialogResult property for this button control should be set to None. -Praveen

Ramesh Praveen [Syncfusion]
Replied On June 25, 2003 11:56 AM UTC

Example: private void okButton_Click(object sender, System.EventArgs e) { if(this.textBox1.Text == String.Empty) MessageBox.Show("Invalid value entered."); else this.DialogResult = DialogResult.OK; }

Ramesh Praveen [Syncfusion]
Replied On June 25, 2003 12:12 PM UTC

Here is another way of doing it: private void TextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (!this.cancelButton_.Focused) { // Do this only when the cancel button is not clicked. if(invalidState) e.Cancel = true; } }


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon