By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,214 IT Pros & Developers. It's quick & easy.

Client side validations for dynamically added user control

P: n/a
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.
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 29, 10:53 am, Shraddha <shraddhajosh...@gmail.comwrote:
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.