aspx thread: Dynamic Validator troubles ...
Hi everybody, I'm using Beta2 and C# ONLY.
This is my problem at this time:
I'm dynamically builiding a table with some input boxes and I need to
validate them.
So I dinamically create some RangeValidators during Page Load and it works
perfectly.
But, when I click on AddBasket Button I need to validate all the Input boxes
created ... and I don't know how to refer them ..
Can anyone help ... ?
Thanks a lot.
Alberto Jacomuzzi
WelolNet s.r.l.
Torino - Italy
MY CODE:
Various Declaration ...
protected System.Web.UI.WebControls.Table MainTable;
protected System.Web.UI.WebControls.TextBox tb;
protected System.Web.UI.WebControls.Button btn_AddBasket;
protected System.Web.UI.WebControls.RangeValidator vld;
private void Page_Load(object sender, System.EventArgs e) {
... Various Stuff ....
int j = 1;
// New Row Declaration
TableRow r = new TableRow();
for (int i = 0; i <= (SizeQtyArray.Length - 1); i++)
{
// New Cell Declaration
c = new TableCell();
TextBox box = new TextBox();
Label lblAvailable = new Label();
RangeValidator vld = new RangeValidator();
// Check if Parameter is not null
if (SizeEANArray[i] == null)
{
box.ID = "NotAvailable";
vld.MaximumValue = "0";
vld.ControlToValidate = "0";
vld.ID = "NotAvailable";
vld.Attributes["Type"] = "String";
}
else
box.ID = "Validator_" + SizeEANArray[i].ToString();
vld.MaximumValue = SizeQtyArray[i].ToString();
vld.MinimumValue = "0";
vld.ID = SizeEANArray[i].ToString();
vld.ControlToValidate = "Validator_" + SizeEANArray[i].ToString();
vld.Attributes["Type"] = "String";
}
// Filling Labels
lblAvailable.Text = SizeQtyArray[i].ToString();
c.Controls.Add(box);
c.Controls.Add(lblAvailable);
r.Cells.Add(c);
j = j + 1;
}
MainTable.Rows.Add(r);
r = new TableRow();
}
// *****************************************************
// TROUBLES AREA !!!!
// When I click AddBasket button, I need to Call my range validators ...
// dynamically created during Page Load (as shown above ....)
// *****************************************************
private void btn_AddBasket_Click(object sender, System.EventArgs e)
{
foreach (string Item in Request.Form)
{
// ******************************************************
// Here I need to call Validate Method for each Text Box created above
// I don't know how to refer them and how to call validation
// ******************************************************
WHAT???.ID = Item;
WHAT???.Validate();
// Call My Methods ....
}
}