A
ad
I want to make a custom web control which composite with a TextBox and a
RequiredFieldValidator;
I set the RequiredFieldValidator's ControlToValidate to the TextBox's ID
(like code below)
But when I use the coustom web control in web form, it throw an exception:
The ControlToValidate can not be empty
How can I set the RequiredFieldValidator's ControlToValidate property?
//##########################################################################
######
public class RequireTextBox : Control, INamingContainer
{
private TextBox box;
RequiredFieldValidator rv;
public string Text
{
get
{
EnsureChildControls();
return box.Text;
}
set
{
EnsureChildControls();
box.Text = value;
}
}
protected override void CreateChildControls()
{
box = new TextBox();
box.Width=30;
Controls.Add(box);
rv= new RequiredFieldValidator();
rv.ControlToValidate=box.ID;
Controls.Add(rv);
}
}
RequiredFieldValidator;
I set the RequiredFieldValidator's ControlToValidate to the TextBox's ID
(like code below)
But when I use the coustom web control in web form, it throw an exception:
The ControlToValidate can not be empty
How can I set the RequiredFieldValidator's ControlToValidate property?
//##########################################################################
######
public class RequireTextBox : Control, INamingContainer
{
private TextBox box;
RequiredFieldValidator rv;
public string Text
{
get
{
EnsureChildControls();
return box.Text;
}
set
{
EnsureChildControls();
box.Text = value;
}
}
protected override void CreateChildControls()
{
box = new TextBox();
box.Width=30;
Controls.Add(box);
rv= new RequiredFieldValidator();
rv.ControlToValidate=box.ID;
Controls.Add(rv);
}
}