Client side validations for dynamically added user control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shraddha

    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
    "trialTextB ox".
    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

    #2
    Re: Client side validations for dynamically added user control

    On May 29, 10:53 am, Shraddha <shraddhajosh.. .@gmail.comwrot e:
    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
    "trialTextB ox".
    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

    Comment

    Working...