Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Validating a Control
Message
 
To
27/01/2005 20:35:28
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00981581
Message ID:
00982566
Views:
20
Mike,
Here is a way to solve your problem:
private void textBox1_Validated(object sender, System.EventArgs e)
{
	if (myValidateTextBox1())
		this.errorProvider1.SetError(this.textBox1,"Error textbox1");
	else
		this.errorProvider1.SetError(this.textBox1,"");
}

private void textBox2_Validated(object sender, System.EventArgs e)
{
	if (myValidateTextBox2())
		this.errorProvider1.SetError(this.textBox2,"Error textbox2");
	else
		this.errorProvider1.SetError(this.textBox2,"");
}

private void textBox3_Validated(object sender, System.EventArgs e)
{
	if (myValidateTextBox3())
		this.errorProvider1.SetError(this.textBox3,"Error textbox3");
	else
		this.errorProvider1.SetError(this.textBox3,"");
}

private bool myValidateTextBox1()
{
  // validation code
  return boolValue
}

private bool myValidateTextBox2()
{
  // validation code
  return boolValue
}

private bool myValidateTextBox3()
{
  // validation code
  return boolValue
}
This way you can call the following code in the save button click:
if (myValidateTextBox1())
{
	this.errorProvider1.SetError(this.textBox1,"Error textbox1");
	return;
}
if (myValidateTextBox2())
{
	this.errorProvider1.SetError(this.textBox2,"Error textbox2");
	return;
}
if (myValidateTextBox3())
{
	this.errorProvider1.SetError(this.textBox3,"Error textbox2");
	return;
}
MessageBox.Show("There were no errors and save can continue!");
I don't know if this is the best way of accomplishing this, but it is atleast one way of doing it.

Hope it helps,
Einar



>Hi Guys,
>
>I created a simple form with 3 textbox control. These 3 textboxes requires a value to be entered, so I use an error provider and put some code in the validating and validated event of the controls. The validation works for each control.
>
>The problem occurs when I tried to enter a value into to first textbox and then clicking the save button without filling up the other 2 textboxes.
>
>What I need is to call the validating event of each textboxes when I click the save button so that the error provider will set the error.
>
>Is this possible? I tried to use the ctrl.invoke method but it does not work. I don't know if I just missed something or the approach is not right.
>
>Here is the sample code that I placed in the click event of the Save button
>
>
>CancelEventArgs ce = new CancelEventArgs(false);
>this.txtDetails.Invoke(new MyDelegate(this.txtDetails_Validating),new object[]{this.txtDetails,ce});
>
>
>this code does not produce an error but it does not do anything either.
>
>Please Help...
>Thanks in advance...
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform