Client side validations for dynamically added user control

S

Shraddha

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.
 
T

Thiago Macedo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top