I have a web form which I generate dynamically by creating questions . I want to enable mandatory fields when a certain routing status is chosen i.e when it is routed to someone and not when the form is rendered initially. I want to add the required
field validators when the form is generated dynamically but not enable the required field validators. I want to enable then only when they are routed to some personnel for verifying data. How to enable these dynamically created required field validators for
dynamic questions using javascript ?????????
Thanks for the reply. What is myValidatorClientID? Is this the
validator ID? Now here is the problem. Since everyquestion is created dynamically on the form it has a questionID generated dynamically and all those quetions have a validator ID which is also generated dynamically with an increment of 1 .
How do i provide these dynamic validator ID's using javascript to activate it?
no, this javascript is for client side. If you want to enable/disable your validator base on some activity on client side.
If you want to enable/disable validator from code behind, there is already a property 'Enabled' availabe. You can use this property to enable/disable validator contorls.
If this post answered your question or solved your problem, please Mark it as Answer.
asp.netUser
Member
15 Points
184 Posts
Dynamic validators
Jul 06, 2012 07:03 PM|LINK
I have a web form which I generate dynamically by creating questions . I want to enable mandatory fields when a certain routing status is chosen i.e when it is routed to someone and not when the form is rendered initially. I want to add the required field validators when the form is generated dynamically but not enable the required field validators. I want to enable then only when they are routed to some personnel for verifying data. How to enable these dynamically created required field validators for dynamic questions using javascript ?????????
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Dynamic validators
Jul 06, 2012 08:38 PM|LINK
you can disable required field validator on page load and enable them using javascript.
function doSomething() { var myVal = document.getElementById('myValidatorClientID'); ValidatorEnable(myVal, false); }asp.netUser
Member
15 Points
184 Posts
Re: Dynamic validators
Jul 06, 2012 09:07 PM|LINK
Hi Ramesh,
Thanks for the reply. What is myValidatorClientID? Is this the validator ID? Now here is the problem. Since everyquestion is created dynamically on the form it has a questionID generated dynamically and all those quetions have a validator ID which is also generated dynamically with an increment of 1 . How do i provide these dynamic validator ID's using javascript to activate it?
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Dynamic validators
Jul 06, 2012 09:19 PM|LINK
Yes, you are right myValidatorClientID is a validator id. You can use the below updated code.
function doSomething(ValidatorClientID) { var myVal = document.getElementById(ValidatorClientID); ValidatorEnable(myVal, false); }you can call this javascript function as
doSomething("<%=myValidator1.ClientID%>");asp.netUser
Member
15 Points
184 Posts
Re: Dynamic validators
Jul 06, 2012 09:21 PM|LINK
You can call this javascript function from code behind right? Do we need to register something ?
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Dynamic validators
Jul 06, 2012 09:26 PM|LINK
no, this javascript is for client side. If you want to enable/disable your validator base on some activity on client side.
If you want to enable/disable validator from code behind, there is already a property 'Enabled' availabe. You can use this property to enable/disable validator contorls.
asp.netUser
Member
15 Points
184 Posts
Re: Dynamic validators
Jul 06, 2012 09:28 PM|LINK
Okay, I see... but i am failing to understand how to do this step?
doSomething("<%=myValidator1.ClientID%>"); Can you provide some links where there is such an example....Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Dynamic validators
Jul 06, 2012 09:32 PM|LINK
so, how do you creating your validators on aspx page?
asp.netUser
Member
15 Points
184 Posts
Re: Dynamic validators
Jul 06, 2012 09:52 PM|LINK
public void addRequiredValidator(Control control, string messageText, PlaceHolder pl)
{
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv" + control.ID;
rfv.ControlToValidate = control.ID;
rfv.ErrorMessage = messageText + " is mandatory. ";
rfv.Display = ValidatorDisplay.None;
rfv.ValidationGroup = "vgSubmit";
}
Ramesh Chand...
Star
12922 Points
2672 Posts
Re: Dynamic validators
Jul 08, 2012 09:51 AM|LINK
okay, so you know for which control you have to disable validator.
With the above code you can get the requried field validator easily.