Validation Controls
Can we create validation controls dynamically at runtime? I had a textbox and a button control on my page and I created a custom validator control in the Page_Load event handler for the textbox to accept M and F only as gender values. But when I run my script, its complaining about the runat=server tag. Any ideas????
Posted Apr 15, 2008, 11:28 AM
Rafiq BatchaPosted Apr 9, 2008, 6:47 PM
Prasanna,
I am not sure whether this approach will help you. Instead of creating validation control on run-time, you may create that control on design time with Enabled="false". It will not work by default. When you click the checkbox, make that validation control is Enable, when its checked. Otherwise make that disable. See the following example:
protected void chkTest_CheckedChanged(object sender, EventArgs e)
{
reqTest.Enabled = chkTest.Checked;
}
When you click the button, you can see how it works.
Posted Apr 9, 2008, 10:23 AM
Rafiq
There is a Details checkbox in the same page. So if the checkbox is ticked I want to validate the textbox. In other case, I want to process the page without validation. Thats why I am creating the validation control at runtime.
Rafiq BatchaPosted Apr 8, 2008, 7:50 PM