开发者

Validate all text boxes in PlaceHolder

I've problem with validating all text boxes in PlaceHolder. I made PlaceHolder and I've no idea how to check that all textboxes have integer numbers as a text. Any ideas?

public void Made_Matrix (PlaceHolder Matrix, int Size){
for(int row=0; row < size; row++){
for(int col=0; col < size; col++){
TextBox TB = New TextBox();
Matrix.Controls.Add(TB);
TB.ID = TB + Convert.ToString(row) + Convert.ToString(col);
TB.AutoPostBack = "true";
}
Matrix.Controls.Add(new LiteralControl ("<br/>"));
}
}
public void TB_Validate (PlaceHolder Matrix, int Size){
for (int row = 0; row < size; row++){
for (int col = 0; col < size; col++){
string Ident = TB + Convert.ToString(row) + Convert开发者_开发百科.ToString(col);

how can i find text hidden in TextBox with ID from Ident? And how to check if it's numeric? I suppose that in .NET there's no function like IsNumeric(), am I right?


Add CompareValidators for every dynamic Textbox with Operator="DataTypeCheck" and Type="Integer". You might also want to define a ValidationGroup f.e. VG_MATRIX for every Validator.


How about Int.TryParse or Double.TryParse for checking the input value?

You can enumerate the controls in the placeholder like this.

foreach (Control control in Matrix.Controls)
{
    TextBox textbox = control as TextBox;
    if (textbox != null)
    {
       // Do stuff with textbox.Text
    }
}

Actually, just do Matrix.FindControl(Ident) as TextBox if you know the exact id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜