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

Avatar of undefined
Last Comment
anyoneis

8/22/2022 - Mon
anyoneis

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

Where is your code? I put mine in Page_Load.

David
sonny_j81

ASKER
I put the code in button .....
ASKER CERTIFIED SOLUTION
anyoneis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61