如何应用动态文本框和验证. [英] how to apply dynamic textboxes and validations.
本文介绍了如何应用动态文本框和验证.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我动态创建了2个文本框.
我希望asp.net要求对这些动态文本框进行验证.
i created 2 textboxes dynamically.
i want asp.net required validation for these Dynamic textboxes.
推荐答案
库玛,
这是我所做的并且正在起作用:
1)我创建了一个TextBox
2)我还动态创建了一个必需的字段验证器,并设置了
将ControlToValidate属性设置为上面创建的TextBox的ID.
3)我已经在div中添加了文本框和必填字段验证器,div在aspx页面中.
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.
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)我在页面上保留了一个按钮,然后在该按钮上单击
必需的字段验证正在触发
希望这对您解决问题有帮助.
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.
这篇关于如何应用动态文本框和验证.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文