RequiredFieldValidator has no action

A

ad

I want to combine a TextBox and a RequiredFieldValidator into to a web
custom control (name RequireTextBox ),
But when I use RequireTextBox in web form, the RequiredFieldValidator has no
action.
How can I do?


{
private TextBox box;
RequiredFieldValidator rv;


public string Text
{
get
{

return box.Text;
}
set
{
box.Text = value;
}
}

protected override void CreateChildControls()
{
box = new TextBox();
box.ID="box";
box.Width=30;
Controls.Add(box);

rv= new RequiredFieldValidator();
rv.ControlToValidate="box";
Controls.Add(rv);
}


}
 
A

ad

Sorry, I forget some code in last post.

I want to combine a TextBox and a RequiredFieldValidator into to a web
custom control (name RequireTextBox ),
But when I use RequireTextBox in web form, the RequiredFieldValidator has no
action.
How can I do?

public class RequireTextBox : Control, INamingContainer
{
private TextBox box;
RequiredFieldValidator rv;


public string Text
{
get
{

return box.Text;
}
set
{
box.Text = value;
}
}

protected override void CreateChildControls()
{
box = new TextBox();
box.ID="box";
box.Width=30;
Controls.Add(box);

rv= new RequiredFieldValidator();
rv.ControlToValidate="box";
Controls.Add(rv);
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top