|  | Client side validations for dynamically added user control |  | |
| | | Shraddha |  |
| Posted: Thu May 29, 2008 1:53 pm Post subject: Client side validations for dynamically added user control |  |
Hi, I am adding some ASP.Net user controls (.ascx file) dynamically on the button click. The user control will get added as many times userhits the button. Now on the click of the submit button, I want to do some form level validations.
For example suppose my .ascx file contains a text box with id say "trialTextBox". Now if user hits the button thrice, 3 user controls will be there on the page and as a result 3 textboxes mentioned above will be there.
Can any one tell me :
1) How can I get access to that user control (.ascx file) through the java script? (While adding that user control I have given unique ids to that user control).
2) If I get access to that user control, how can I access the controls (Like text box mentioned earlier) and its values.
Any help or hint will be appreciated. |
| |
| | | Thiago Macedo |  |
| Posted: Thu May 29, 2008 2:58 pm Post subject: Re: Client side validations for dynamically added user contr |  |
| |  | |
On May 29, 10:53 am, Shraddha <shraddhajosh...@gmail.com> wrote:
| Quote: | Hi, I am adding some ASP.Net user controls (.ascx file) dynamically on the button click. The user control will get added as many times userhits the button. Now on the click of the submit button, I want to do some form level validations.
For example suppose my .ascx file contains a text box with id say "trialTextBox". Now if user hits the button thrice, 3 user controls will be there on the page and as a result 3 textboxes mentioned above will be there.
Can any one tell me :
1) How can I get access to that user control (.ascx file) through the java script? (While adding that user control I have given unique ids to that user control).
2) If I get access to that user control, how can I access the controls (Like text box mentioned earlier) and its values.
Any help or hint will be appreciated.
|
Hello,
For start, you can't access the user control via JS. It's a server side control which results in an HTML response. That response is what you'll check with JavaScript.
There're many methods to such task. The first (and simpliest) I get in mind is use the ClientId property of the txt control to get the (unique) IDs of the textbox and then validate them with Javascript. You could send it (the ids) to a hidden input, incrementing it dynamically as the user adds the UsrCtr. With this hidden text field populated with the unique ids of the text controls (comma separated or whatever) loop (js) through them validating as you wish.
Hope this helps.
Thiago |
| |
|
|