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 INamingContaine r, it works fine, but then I lose
viewstate for the child controls.
I will appreciate any help a lot!
CustomControl.c s
-----------------------------------------------
public class CustomControl : WebControl, INamingContaine r
{
protected override void CreateChildCont rols()
{
//
TextBox t = new TextBox();
t.ID = "t";
Controls.Add(t) ;
//
RequiredFieldVa lidator r = new RequiredFieldVa lidator();
r.ErrorMessage = "Error Message";
r.ControlToVali date = "t";
Controls.Add(r) ;
//
Button b = new Button();
b.Text = "Validate";
Controls.Add(b) ;
}
}
Default.aspx
-----------------------------------------------
....
<html>
...
<form runat="server">
<namespace:Cust omControl 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 INamingContaine r, it works fine, but then I lose
viewstate for the child controls.
I will appreciate any help a lot!
CustomControl.c s
-----------------------------------------------
public class CustomControl : WebControl, INamingContaine r
{
protected override void CreateChildCont rols()
{
//
TextBox t = new TextBox();
t.ID = "t";
Controls.Add(t) ;
//
RequiredFieldVa lidator r = new RequiredFieldVa lidator();
r.ErrorMessage = "Error Message";
r.ControlToVali date = "t";
Controls.Add(r) ;
//
Button b = new Button();
b.Text = "Validate";
Controls.Add(b) ;
}
}
Default.aspx
-----------------------------------------------
....
<html>
...
<form runat="server">
<namespace:Cust omControl runat="server" id="id" />
</form>
...
</html>