Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dominik 711 posts 733 karma points
    Mar 31, 2011 @ 10:34
    dominik
    0

    use usercontrol more than once in one page - problem

    Hi everybody,

    We have the following scenario:

    A usercontrol/macro which generats some HTML (with some specific ids and javascript). If this usercontrol is used in the page once - it works

    Now i just added the same usecontrol/macro on another position of the same page template and now each id exist more than once and javascript does not know which id it has to show.

    So now my question is how to solve this problem. We have to generate all the HTML only once. I just thought about looking in the usercontrol if the id of the div still exists and only generate the html if it does not exist.

    Is there any other solution for it?

     

  • kows 81 posts 151 karma points c-trib
    Mar 31, 2011 @ 11:32
    kows
    0

    use guids / add the usercontrols clientid to each id.

  • dominik 711 posts 733 karma points
    Mar 31, 2011 @ 11:34
    dominik
    0

    but if the user is on another page and opens the usercontrol it should be opened. Is this working with guids? Or does it store the information in session or cookie?

    Thanks

  • Laurent Lequenne 123 posts 248 karma points
    Mar 31, 2011 @ 11:40
    Laurent Lequenne
    0

    The solution is a better design ! If you are using Jquery and selectors, do not rely on ids ! Unique IDs are only generated for server controls :

    <div id="myid"></div> => will be rendered multiple times with the same id

    <div id="myid" runat="server"></div> : id will be recreated by the server.

    To access your id in your javascript. IF it's on the usercontrol use $('#<%=myid.ClientID%>) or ClientId ?  I never know :-) If not you need to passe the id somehow to your external JS

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft