Composite WebControl validator problem

J

Jacob

Hello,

I am creating a framework of custom webcontrols, for example, a
combined textbox and validator. I need to be able to add the validator
dynamically.

My problem is that the validator doesn't react when my form is
submitted.

The code below is a simple example that reproduces the behaviour.
Without implementing INamingContainer, it works fine, but then I lose
viewstate for the child controls.

I will appreciate any help a lot!


CustomControl.cs
-----------------------------------------------
public class CustomControl : WebControl, INamingContainer
{
protected override void CreateChildControls()
{
//
TextBox t = new TextBox();
t.ID = "t";

Controls.Add(t);

//
RequiredFieldValidator r = new RequiredFieldValidator();
r.ErrorMessage = "Error Message";
r.ControlToValidate = "t";

Controls.Add(r);

//
Button b = new Button();
b.Text = "Validate";

Controls.Add(b);
}
}


Default.aspx
-----------------------------------------------
....
<html>
...
<form runat="server">
<namespace:CustomControl runat="server" id="id" />
</form>
...
</html>
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top