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>
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>