Link to home
Start Free TrialLog in
Avatar of sonny_j81
sonny_j81

asked on

Dynamically created RegularExpressionValidator in c# code behind

Dear Expert,

I wanna to dynamically add the RegularExpressionValidator in c# code behind..
May i know how to do that?
actually i have test the RegularExpressionValidator in html there..It can get d result that i want.
but once i write d RegularExpressionValidator in code behind it, the regular expression didnt appear when i key in wrong number.
May i know how to write dynamic RegularExpressionValidator?Do i need to write txtEvalTitle_onTextChanged ?

Bellow is my code:

                            TextBox txtEvalTitle = new TextBox();
                            txtEvalTitle.ID = "txtEvalTitle" + arrCriteriaDetails[i, 5];  
                            txtEvalTitle.Font.Bold = true;
                            txtEvalTitle.Font.Size = 10;
                            txtEvalTitle.Width = 30;
                            txtEvalTitle.Text = arrCriteriaDetails[i, 3];
                            RegularExpressionValidator rev = new RegularExpressionValidator();
                            rev.ID = "rev" + arrCriteriaDetails[i, 3];
                            rev.ControlToValidate = "txtEvalTitle" + arrCriteriaDetails[i, 5];
                            rev.ErrorMessage = "Please Enter Title No";
                            rev.ValidationExpression = "[-+]?([1-9]*\\.0+)";
                            rev.Visible = true;
                           
                            phCriteriaDetails.Controls.Add(txtEvalTitle);
                           
                            phCriteriaDetails.Controls.Add(rev);  


urgently need ur help..
Thanks
Avatar of anyoneis
anyoneis
Flag of United States of America image

What is phCriteriaDetails - I made it a panel and the code worked fine.

Where is your code? I put mine in Page_Load.

David
Avatar of sonny_j81
sonny_j81

ASKER

I put the code in button .....
ASKER CERTIFIED SOLUTION
Avatar of anyoneis
anyoneis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial