Click here to Skip to main content
15,881,769 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i created 2 textboxes dynamically.

i want asp.net required validation for these Dynamic textboxes.
Posted
Comments
CodeHawkz 7-Sep-12 7:52am    
*facepalm* Are you like serious? I would love to know how on earth you expected us to figure out how you created the textbox dynamically and what is the name of it and the what is the validation you want and so on. Am sorry, but after seeing so many people posting questions this way over and over again, it's impossible to believe how many people don't have the common sense to tell their problem to another person properly even.
kumar2233 7-Sep-12 8:11am    
it's serious. Actually it is my requirement. I created 2 dynamically textboxes and 1 button.

suppose i click button 2 dynamically textboxes validation are not fired.

plz tell me.
[no name] 7-Sep-12 11:07am    
"plz tell me", I do not know who plz is but I will tell you that we cannot tell you anything. If you read through CodeHawkz frustration you will see that he (or she) plainly told you why. "how you created the textbox dynamically and what is the name of it and the what is the validation you want and so on". No one on this site can see your code, your project or read your mind.

1 solution

Hi Kumar,
This is what I have done and it is working:
1) I have created a TextBox
2) I have created a required field validator also dynamically and set the
ControlToValidate property to the ID of the above created TextBox.
3) I have added both text box and required field validator to a div, div is there in the aspx page.

C#
TextBox txt = new TextBox();
txt.ID = "DynControl";

RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ErrorMessage = "Error is for Dynamic Control";
rfv.BorderColor = Color.Red;
rfv.ControlToValidate = "DynControl";

divTest.Controls.Add(txt);//This is the div i spoke about in 3rd point
divTest.Controls.Add(rfv);  

4) I kept a button in the page and on this button click,
Required field validation is firing

I hope this will help you in resolving your issue.
 
Share this answer
 
v2
Comments
Mohamed Mitwalli 7-Sep-12 11:36am    
5+
Member 13564463 15-Dec-17 1:59am    
I need a Answer For Regular expression Validation in Time Format"HH:MM" in this sence....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900