For Validating the MinLengthTest for a textbox i used the following coding their is an error showing :"THE NAME 'txtMinLengthTest ' does not exist in the current context.Please resolve my problem where i need to initialize this 'txtMinLengthTest '
Thanks in Advance.
private void txtMinLengthTest_Validated(object sender, EventArgs e)
{
bool bTest = txtMinLengthTestIsValid();
if (bTest == true)
{
this.errorProvider1.SetError(txtMinLengthTest, "The field must contain a minimum of 7 characters");
}
else
{
this.errorProvider1.SetError(txtMinLengthTest, " ");
}
}
// Test to see that the textbox contains a minimum number of characters
private bool txtMinLengthTestIsValid()
{
char[] testArr = txtMinLengthTest.Text.ToCharArray();
bool testBool = false;
if (testArr.Length < 7)
{
testBool = true;
}
return testBool;
}
}
Loading
VulpesPosted Jun 15, 2012, 4:55 AM
Rubi BegumPosted Jun 14, 2012, 10:28 PM
VulpesPosted Jun 14, 2012, 12:36 PM
How did you add the txtMinLengthTest_Validated eventhandler - did you add it via the events list in the Properties Box or did you simply type it in?
Rubi BegumPosted Jun 14, 2012, 11:58 AM
the error that i was getting is "txtMinLengthTest" does not exist in the current context how to resolve that error, can i use textbox1 in place of txtMinLengthTest plz reply
Santhosh Kumar JayaramanPosted Jun 14, 2012, 3:45 AM
private void txtMinLengthTest_Validated(object sender, EventArgs e)
{
Textbox txtbox=(TextBox) sender;
bool bTest = txtMinLengthTestIsValid(txtbox);
if (bTest == true)
{
this.errorProvider1.SetError(txtMinLengthTest, "The field must contain a minimum of 7 characters");
}
else
{
this.errorProvider1.SetError(txtMinLengthTest, " ");
}
}
// Test to see that the textbox contains a minimum number of characters
private bool txtMinLengthTestIsValid(TextBox txtbox)
{
char[] testArr = txtbox.Text.ToCharArray();
bool testBool = false;
if (testArr.Length < 7)
{
testBool = true;
}
return testBool;
}
}